Class: Solr::Request::AddDocument

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

Overview

The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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])


27
28
29
30
31
32
33
34
# File 'lib/solr/request/add_document.rb', line 27

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



38
39
40
41
42
43
44
# File 'lib/solr/request/add_document.rb', line 38

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