Class: Solr::Request::AtomicUpdate

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

Instance Method Summary collapse

Methods inherited from Update

#handler, #response_format

Methods inherited from Base

#handler, #response_format

Constructor Details

#initialize(update_docs) ⇒ AtomicUpdate

Example: Solr::Request::AtomicUpdate.new([:id => 10, :set => => “new value”])



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/solr/request/atomic_update.rb', line 3

def initialize(update_docs)
  @docs = []
  update_docs.each do |update_doc|
    doc = {}
    [:set, :add, :remove, :removeregex, :inc].each do |mode|
      field_data = update_doc[mode]
      if field_data
        field_data.each do |field_name, field_value|
          doc[field_name] = {mode => field_value} if field_value
        end
        update_doc.delete mode
      end
    end
    doc[update_doc.keys[0].to_s] = update_doc.values[0]
    @docs << doc
  end
end

Instance Method Details

#content_typeObject



21
22
23
# File 'lib/solr/request/atomic_update.rb', line 21

def content_type
  'application/json; charset=utf-8'
end

#to_sObject

returns the request as a string suitable for posting



26
27
28
# File 'lib/solr/request/atomic_update.rb', line 26

def to_s
  return @docs.to_json
end