Class: XapianDb::PersistentDatabase
- Defined in:
- lib/xapian_db/database.rb
Overview
Persistent database on disk
Instance Method Summary collapse
-
#commit ⇒ Object
Commit all pending changes.
-
#initialize(options) ⇒ PersistentDatabase
constructor
Constructor.
-
#reader ⇒ Xapian::Database
Get a readable instance of the database.
-
#writer ⇒ Xapian::WritableDatabase
The writer is instantiated layzily to avoid a permanent write lock on the database.
Methods inherited from Database
#delete_doc_with_unique_term, #delete_docs_of_class, #facets, #find_similar_to, #search, #size, #store_doc
Methods included from Utilities
#assert_valid_keys, #camelize, #constantize
Constructor Details
#initialize(options) ⇒ PersistentDatabase
Constructor
214 215 216 217 218 219 220 221 222 223 |
# File 'lib/xapian_db/database.rb', line 214 def initialize() @path = [:path] @db_flag = [:create] ? Xapian::DB_CREATE_OR_OVERWRITE : Xapian::DB_OPEN if [:create] # make sure the path exists; Xapian will not create the necessary directories FileUtils.makedirs @path @writer = Xapian::WritableDatabase.new(@path, @db_flag) end @reader = Xapian::Database.new(@path) end |
Instance Method Details
#commit ⇒ Object
Commit all pending changes
240 241 242 |
# File 'lib/xapian_db/database.rb', line 240 def commit writer.commit end |
#reader ⇒ Xapian::Database
Get a readable instance of the database
227 228 229 |
# File 'lib/xapian_db/database.rb', line 227 def reader Xapian::Database.new(@path) end |
#writer ⇒ Xapian::WritableDatabase
The writer is instantiated layzily to avoid a permanent write lock on the database. Please note that you will get locking exceptions if you open the same database multiple times and access the writer in more than one instance!
235 236 237 |
# File 'lib/xapian_db/database.rb', line 235 def writer @writer ||= Xapian::WritableDatabase.new(@path, @db_flag) end |