Module: Xapor::ModelIntegration::ClassMethods
- Defined in:
- lib/xapor/model_integration.rb
Instance Method Summary collapse
- #reset_index ⇒ Object
- #search(query) ⇒ Object
- #xapor ⇒ Object
- #xapor_config ⇒ Object
- #xapor_db ⇒ Object
Instance Method Details
#reset_index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/xapor/model_integration.rb', line 15 def reset_index if @db @db.flush @db.ro.close @db.rw.close end @db = XapianDb.new(xapor_config.xapian_fu_db.merge(:overwrite => true)) if block_given? yield @db end end |
#search(query) ⇒ Object
11 12 13 |
# File 'lib/xapor/model_integration.rb', line 11 def search(query) xapor_db.search(query) end |
#xapor ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xapor/model_integration.rb', line 8 def xapor include XapianFu def search(query) xapor_db.search(query) end def reset_index if @db @db.flush @db.ro.close @db.rw.close end @db = XapianDb.new(xapor_config.xapian_fu_db.merge(:overwrite => true)) if block_given? yield @db end end def xapor_config self.class.instance_variable_get(:@config) end def xapor_db @db ||= XapianDb.new(xapor_config.xapian_fu_db.merge(:create => true)) end @config = Xapor::Config.new if block_given? yield @config end @config.search_fields.each do |field| class_eval("def self.search_by_#{field}(query)\nself.search(query)\nend") end if defined? ActiveRecord && ancestors.includes(ActiveRecord::Base) after_save :add_to_index after_destroy :remove_from_index #in-memory index, needs to be indexed on startup all.each {|o| o.add_to_index} unless @config.directory_config end end |
#xapor_config ⇒ Object
27 28 29 |
# File 'lib/xapor/model_integration.rb', line 27 def xapor_config self.class.instance_variable_get(:@config) end |
#xapor_db ⇒ Object
31 32 33 |
# File 'lib/xapor/model_integration.rb', line 31 def xapor_db @db ||= XapianDb.new(xapor_config.xapian_fu_db.merge(:create => true)) end |