Class: Sunspot::RichDocument

Inherits:
RSolr::Xml::Document
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sunspot/rich_document.rb

Instance Method Summary collapse

Instance Method Details

#add(connection) ⇒ Object



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
# File 'lib/sunspot/rich_document.rb', line 15

def add(connection)
  params = {
    :wt => :ruby
  }

  data = nil

  @fields.each do |f|
    if f.name.to_s.include?("_attachment") and f.value.present?
      params['fmap.content'] = f.name
      if f.value.is_a?(Hash)
        params['stream.url']         = f.value[:file]
        params['stream.contentType'] = f.value[:type]
      else
        data = open(f.value).read rescue ""
      end
    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.attrs[:boost]
      params["boost.#{f.name.to_s}"] = f.attrs[:boost]
    end
  end

  connection.send_and_receive('update/extract', 
    { :method => :post, 
      :params => params, 
      :data => data, 
      :headers => {"Content-Type" => ""}
    })
end

#contains_attachment?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
# File 'lib/sunspot/rich_document.rb', line 6

def contains_attachment?
  @fields.each do |field|
    if field.name.to_s.include?("_attachment") && field.value.present?
      return true
    end
  end
  return false
end