forked from sunspot/sunspot
/
rich_document.rb
45 lines (39 loc) · 1.28 KB
/
rich_document.rb
1
2
3
4
5
6
7
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
module Sunspot
class RichDocument < RSolr::Message::Document
include Enumerable
def contains_attachment?
@fields.each do |field|
if field.name.to_s.include?("_attachment")
return true
end
end
return false
end
def add(connection)
params = {
:wt => :ruby,
'idx.attr' => false, # don't index any attributes, unless explicitly mapped
'ignore.und.fl' => true, # ignore all undefined fields
'map.title' => 'title_text',
}
@fields.each do |f|
puts f.name.to_s + " " + f.value.to_s
if f.name.to_s.include?("_attachment")
params["resource.name"] = f.value # TIKA-154 workaround
params["stream.file"] = f.value
params['def.fl'] = f.name, # all text extracted goes to text_t (since it is a stored field, for highlighting)
params['fmap.content'] = f.name
else
param_name = "literal.#{f.name.to_s}"
params[param_name] = [] unless params.has_key?(param_name)
params[param_name] << f.value
end
# if f.boost
# params["boost.#{f.name.to_s}"] = f.boost
# end
end
solr_message = params
pp connection.send('update/extract', solr_message)
end
end
end