Class: Solr::Request::AddDocument

Inherits:
Update show all
Defined in:
lib/solr/request/add_document.rb

Instance Method Summary collapse

Methods inherited from Update

#handler, #response_format

Methods inherited from Base

#content_type, #handler, #response_format

Constructor Details

#initialize(doc = {}) ⇒ AddDocument

create the request, optionally passing in a Solr::Document

request = Solr::Request::AddDocument.new doc

as a short cut you can pass in a Hash instead:

request = Solr::Request::AddDocument.new :creator => 'Jorge Luis Borges'

or an array, to add multiple documents at the same time:

request = Solr::Request::AddDocument.new([doc1, doc2, doc3])


32
33
34
35
36
37
38
39
# File 'lib/solr/request/add_document.rb', line 32

def initialize(doc={})
  @docs = []
  if doc.is_a?(Array)
    doc.each { |d| add_doc(d) }
  else
    add_doc(doc)
  end
end

Instance Method Details

#to_sObject

returns the request as a string suitable for posting



43
44
45
46
47
48
49
# File 'lib/solr/request/add_document.rb', line 43

def to_s
  e = Solr::XML::Element.new 'add'
  for doc in @docs
    e.add_element doc.to_xml
  end
  return e.to_s
end