Class: ActsAsXapian::ReadableIndex
- Defined in:
- lib/acts_as_xapian/readable_index.rb
Constant Summary collapse
- @@available_indicies =
{}
Instance Attribute Summary collapse
-
#enquire ⇒ Object
readonly
Returns the value of attribute enquire.
-
#query_parser ⇒ Object
readonly
Returns the value of attribute query_parser.
-
#values_by_prefix ⇒ Object
readonly
Returns the value of attribute values_by_prefix.
Class Method Summary collapse
-
.index_for(models) ⇒ Object
Takes an array of model classes and returns an index object to be used for searching across the given models.
Instance Method Summary collapse
-
#initialize(models) ⇒ ReadableIndex
constructor
Opens the db for reading and builds the query parser.
-
#reset_enquire! ⇒ Object
Creates a new search session.
Methods inherited from Index
Constructor Details
#initialize(models) ⇒ ReadableIndex
Opens the db for reading and builds the query parser
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/acts_as_xapian/readable_index.rb', line 26 def initialize(models) raise NoXapianRubyBindingsError.new("Xapian Ruby bindings not installed") unless ActsAsXapian.bindings_available raise "acts_as_xapian hasn't been called in any models" if @@init_values.empty? self.class.prepare_environment # basic Xapian objects begin @db = Xapian::Database.new(@@db_path) @enquire = Xapian::Enquire.new(@db) rescue IOError raise "Xapian database not opened; have you built it with rake xapian:rebuild_index ?" end init_query_parser(models) end |
Instance Attribute Details
#enquire ⇒ Object (readonly)
Returns the value of attribute enquire.
5 6 7 |
# File 'lib/acts_as_xapian/readable_index.rb', line 5 def enquire @enquire end |
#query_parser ⇒ Object (readonly)
Returns the value of attribute query_parser.
5 6 7 |
# File 'lib/acts_as_xapian/readable_index.rb', line 5 def query_parser @query_parser end |
#values_by_prefix ⇒ Object (readonly)
Returns the value of attribute values_by_prefix.
5 6 7 |
# File 'lib/acts_as_xapian/readable_index.rb', line 5 def values_by_prefix @values_by_prefix end |
Class Method Details
.index_for(models) ⇒ Object
Takes an array of model classes and returns an index object to be used for searching across the given models
Prevents query parser interaction across multiple models unless performing a multi model search
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/acts_as_xapian/readable_index.rb', line 12 def self.index_for(models) index_key = models.map {|m| m.to_s }.sort.join('---') if @@available_indicies.key?(index_key) index = @@available_indicies[index_key] index.reset_enquire! index else index = self.new(models) @@available_indicies[index_key] = index index end end |
Instance Method Details
#reset_enquire! ⇒ Object
Creates a new search session
44 45 46 47 48 49 |
# File 'lib/acts_as_xapian/readable_index.rb', line 44 def reset_enquire! @db.reopen # This grabs the latest db updates @enquire = Xapian::Enquire.new(@db) rescue IOError raise "Xapian database not opened; have you built it with rake xapian:rebuild_index ?" end |