40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/acts_as_estraier_doc.rb', line 40
def est_search(phrase, options = {})
cond = EstraierPure::Condition::new
condition_options = 0
if options.include? :condition_options
options[:condition_options].to_a.each do |condition_option|
condition_options = condition_options | condition_option
end
else
condition_options = self.configuration[:condition_options]
end
cond.set_options(condition_options)
cond.set_phrase(phrase.to_s)
options[:attributes].to_a.each { |attribute| cond.add_attr(attribute) } if options.include? :attributes
cond.set_max(options[:limit]) if options.include? :limit
cond.set_skip(options[:offset]) if options.include? :offset
cond.set_order(options[:order]) if options.include? :order
wwidth = options.include?(:snippet_wwidth) ? options[:snippet_wwidth] : 480
hwidth = options.include?(:snippet_hwidth) ? options[:snippet_hwidth] : -1
awidth = options.include?(:snippet_awidth) ? options[:snippet_awidth] : -1
self.estraier_conn.set_snippet_width(wwidth, hwidth, awidth)
Rails.logger.info cond.inspect if options[:debug]
result = {:records => [], :info => {}}
rs = self.estraier_conn.search(cond, options.include?(:depth) ? options[:depth] : 0)
if rs
docs = {}
ids = []
rs.each do |doc|
docs[doc.attr('record_id').to_i] = doc
ids << doc.attr('record_id').to_i
end
records = self.find :all, :conditions => {:id => ids}, :include => options[:include]
(ids - records.map(&:id)).each do |orphaned_id|
Rails.logger.info "[EstDoc] Remove orphaned index #{orphaned_id}"
self.estraier_conn.out_doc docs[orphaned_id].attr('@id')
end
result[:records] = records.map{|record| record.estdoc = docs[record.id]; record}
HINT_KEYS.each{|key| result[:info][key.downcase.to_sym] = rs.hint key}
else
raise
end
return result
end
|