class XapianDb::PersistentDatabase

Persistent database on disk

Public Class Methods

new(options) click to toggle source

Constructor @param [Hash] options Options for the persistent database @option options [String] :path A path to the file system @option options [Boolean] :create Should the database be created? Will overwrite an existing database if true! @example Force the creation of a database. Will overwrite an existing database

db = XapianDb::PersistentDatabase.new(:path => "/tmp/mydb", :create => true)

@example Open an existing database. The database must exist

db = XapianDb::PersistentDatabase.new(:path => "/tmp/mydb", :create => false)
    # File lib/xapian_db/database.rb
214 def initialize(options)
215   @path    = options[:path]
216   @db_flag = options[:create] ? Xapian::DB_CREATE_OR_OVERWRITE : Xapian::DB_OPEN
217   if options[:create]
218     # make sure the path exists; Xapian will not create the necessary directories
219     FileUtils.makedirs @path
220     @writer = Xapian::WritableDatabase.new(@path, @db_flag)
221   end
222   @reader = Xapian::Database.new(@path)
223 end

Public Instance Methods

commit() click to toggle source

Commit all pending changes

    # File lib/xapian_db/database.rb
240 def commit
241   writer.commit
242 end
reader() click to toggle source

Get a readable instance of the database @return [Xapian::Database] A readable xapian database (see xapian.org/docs/apidoc/html/classXapian_1_1Database.html)

    # File lib/xapian_db/database.rb
227 def reader
228   Xapian::Database.new(@path)
229 end
writer() click to toggle source

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! @return [Xapian::WritableDatabase] A xapian database that is writable (see xapian.org/docs/apidoc/html/classXapian_1_1WritableDatabase.html)

    # File lib/xapian_db/database.rb
235 def writer
236   @writer ||= Xapian::WritableDatabase.new(@path, @db_flag)
237 end