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
|
# File 'lib/xapor/model_integration.rb', line 14
def xapor
class << self
include XapianFu
def search(query)
xapor_db.search(query)
end
def xapor_config
@config
end
def xapor_db
@db ||= XapianDb.new(@config.xapian_fu_db, :create => true)
end
end
if defined?(ActiveRecord) && self.is_a?(ActiveRecord::Base)
self.send(:after_save, :add_to_index)
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
end
|