Class: Solr::Request::ModifyDocument

Inherits:
Update
  • Object
show all
Defined in:
lib/solr/request/modify_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

#response_format

Methods inherited from Base

#content_type, #response_format

Constructor Details

#initialize(update_data) ⇒ ModifyDocument

Example: ModifyDocument.new(:id => 10, :overwrite => => “new value”)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solr/request/modify_document.rb', line 16

def initialize(update_data)
  modes = []
  @doc = {}
  [:overwrite, :append, :distinct, :increment, :delete].each do |mode|
    field_data = update_data[mode]
    if field_data
      field_data.each do |field_name, field_value|
        modes << "#{field_name}:#{mode.to_s.upcase}"
        @doc[field_name] = field_value if field_value  # if value is nil, omit so it can be removed
      end
      update_data.delete mode
    end
  end
  @mode = modes.join(",")
  
  # only one key should be left over, the id
  @doc[update_data.keys[0].to_s] = update_data.values[0]
end

Instance Method Details

#handlerObject



42
43
44
# File 'lib/solr/request/modify_document.rb', line 42

def handler
  "update?mode=#{@mode}"
end

#to_sObject

returns the request as a string suitable for posting



36
37
38
39
40
# File 'lib/solr/request/modify_document.rb', line 36

def to_s
  e = Solr::XML::Element.new 'add'
  e.add_element(Solr::Document.new(@doc).to_xml)
  return e.to_s
end