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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/mongoid_sphinx/delta.rb', line 16
def update_indeces
attrs = self.changes.select do |key, value|
self.search_fields.include?(key) || self.search_attributes.include?(key)
end
attribute_names = attrs.keys.collect{|key| key.to_s}
self.search_attributes.each do |key, value|
case value.class
when Hash
entries = []
self.document_hash[key.to_s].to_a.each do |entry|
entries << entry.join(" : ")
end
attrs[key] = entries.join(", ")
when Array
attrs[key] = self.document_hash[key.to_s].join(", ")
when Date
attrs[key] = self.document_hash[key.to_s].to_time.to_i
when DateTime || Time
attrs[key] = self.document_hash[key.to_s].to_i
when Boolean
attrs[key] = self.document_hash[key.to_s] ? 1 : 0
else
attrs[key] = self.document_hash[key.to_s].to_s
end
end
self.search_fields.each do |key|
if document_hash[key.to_s].is_a?(Array)
attrs[key] = "<#{key}><![CDATA[[#{document_hash[key.to_s].join(", ")}]]></#{key}>"
elsif document_hash[key.to_s].is_a?(Hash)
entries = []
document_hash[key.to_s].to_a.each do |entry|
entries << entry.join(" : ")
end
attrs[key] = "<#{key}><![CDATA[[#{entries.join(", ")}]]></#{key}>"
else
attrs[key] = "<#{key}><![CDATA[[#{document_hash[key.to_s]}]]></#{key}>"
end
end
attribute_values = attrs.values
update_index self.class.sphinx_index.core_name, attribute_names, attribute_values
update_index self.class.sphinx_index.delta_name, attribute_names, attribute_values
end
|