module XapianDb
daemon script to manage the beanstalk worker daemon @author Gernot Kogler
@author Gernot Kogler
This writer writes changes directly to the open database. Use the direct writer only for single process environments (one single rails app server, e.g. one mongrel). For multi process environemnts you should use a writer that processes index changes through a queue. @author Gernot Kogler
This writer is a dummy writer that simply does nothing. @author Gernot Kogler
This writer collects index change requests but does not submit them immediately to the database. The index changes are applied when the commit method is called. This writer is intended for internal use only. Do not use it in a xapian configuration! @author Gernot Kogler
Collection of utility methods @author Gernot Kogler
Constants
- LANGUAGE_MAP
-
Supported languages
Public Class Methods
Source
# File lib/xapian_db.rb 165 def self.auto_indexing_disabled(&block) 166 execute_block :writer => XapianDb::IndexWriters::NoOpWriter do 167 block.call 168 end 169 170 end
Execute a block and do not update the index
Source
# File lib/xapian_db.rb 56 def self.create_db(options = {}) 57 if options[:path] 58 PersistentDatabase.new(:path => options[:path], :create => true) 59 else 60 InMemoryDatabase.new 61 end 62 end
Create a database @param [Hash] options @option options [String] :path A path to the file system. If no path is
given, creates an in memory database. <b>Overwrites an existing database!</b>
@return [XapianDb::Database]
Source
# File lib/xapian_db.rb 81 def self.database 82 XapianDb::Config.database 83 end
Access the configured database. See {XapianDb::Config.setup} for instructions on how to configure a database @return [XapianDb::Database]
Source
# File lib/xapian_db.rb 115 def self.delete_doc_with(xapian_id, commit=true) 116 writer = Thread.current[:xapian_db_block_writer] || XapianDb::Config.writer 117 writer.delete_doc_with xapian_id, commit 118 end
Remove a document from the index @param [String] xapian_id The document id
Source
# File lib/xapian_db.rb 176 def self.execute_block(opts, &block) 177 Thread.current[:xapian_db_block_writer] = opts[:writer] 178 begin 179 block.call 180 rescue Exception => ex 181 if opts[:error_message] 182 if defined?(Rails) 183 Rails.logger.error opts[:error_message] 184 else 185 puts opts[:error_message] 186 end 187 end 188 raise 189 ensure 190 # release the block writer 191 Thread.current[:xapian_db_block_writer] = nil 192 end 193 end
execute a block of code with a given writer and handle errors @param [Hash] opts Options @option opts [Object] :writer An index writer @option opts [String] :error_message the error message to log if an error occurs
Source
# File lib/xapian_db.rb 102 def self.facets(attribute, expression) 103 XapianDb::Config.database.facets attribute, expression 104 end
Get facets from the configured database. See {XapianDb::Database#facets} for options @return [Hash<Class, Integer>] A hash containing the classes and the hits per class
Source
# File lib/xapian_db.rb 108 def self.index(obj, commit=true, changed_attrs: []) 109 writer = Thread.current[:xapian_db_block_writer] || XapianDb::Config.writer 110 writer.index obj, commit, changed_attrs: changed_attrs 111 end
Update an object in the index @param [Object] obj An instance of a class with a blueprint configuration
Source
# File lib/xapian_db.rb 70 def self.open_db(options = {}) 71 if options[:path] 72 PersistentDatabase.new(:path => options[:path], :create => false) 73 else 74 InMemoryDatabase.new 75 end 76 end
Open a database @param [Hash] options @option options [String] :path A path to the file system. If no path is
given, creates an in memory database. If a path is given, then database must exist.
@return [XapianDb::Database]
Source
# File lib/xapian_db.rb 144 def self.rebuild_xapian_index(options={}) 145 configured_classes = XapianDb::DocumentBlueprint.configured_classes 146 return false unless configured_classes.size > 0 147 configured_classes.each do |klass| 148 if klass.respond_to?(:rebuild_xapian_index) 149 XapianDb::Config.writer.reindex_class(klass, options) 150 end 151 end 152 true 153 end
Rebuild the xapian index for all configured blueprints @param [Hash] options Options for reindexing @option options [Boolean] :verbose (false) Should the reindexing give status informations? @return [Boolean] Did we reindex anything?
Source
# File lib/xapian_db.rb 122 def self.reindex(object, commit=true, changed_attrs: []) 123 writer = Thread.current[:xapian_db_block_writer] || XapianDb::Config.writer 124 blueprint = XapianDb::DocumentBlueprint.blueprint_for object.class.name 125 if blueprint.should_index?(object) 126 writer.index object, commit, changed_attrs: changed_attrs 127 else 128 writer.delete_doc_with object.xapian_id, commit 129 end 130 end
Update or delete a xapian document belonging to an object depending on the ignore_if logic(if present) @param [Object] object An instance of a class with a blueprint configuration
Source
# File lib/xapian_db.rb 136 def self.reindex_class(klass, options={}) 137 XapianDb::Config.writer.reindex_class klass, options 138 end
Reindex all objects of a given class @param [Class] klass The class to reindex @param [Hash] options Options for reindexing @option options [Boolean] :verbose (false) Should the reindexing give status informations?
Source
# File lib/xapian_db.rb 88 def self.search(expression, options={}) 89 order = options.delete :order 90 if order 91 attr_names = [order].flatten 92 undefined_attrs = attr_names - XapianDb::DocumentBlueprint.attributes 93 raise ArgumentError.new "invalid order clause: attributes #{undefined_attrs.inspect} are not defined" unless undefined_attrs.empty? 94 options[:sort_indices] = attr_names.map {|attr_name| XapianDb::DocumentBlueprint.value_number_for(attr_name) } 95 end 96 XapianDb::Config.database.search(expression, options) 97 end
Query the configured database. See {XapianDb::Database#search} for options @return [XapianDb::Resultset]
Source
# File lib/xapian_db.rb 46 def self.setup(&block) 47 XapianDb::Config.setup(&block) 48 @writer = XapianDb::Config.writer 49 end
Global configuration for XapianDb
. See {XapianDb::Config.setup} for available options
Source
# File lib/xapian_db.rb 156 def self.transaction(&block) 157 writer = XapianDb::IndexWriters::TransactionalWriter.new 158 execute_block :writer => writer, :error_message => "error in XapianDb transaction block, transaction aborted" do 159 block.call 160 writer.commit_using XapianDb::Config.writer 161 end 162 end
Execute a block as a transaction