class RSolr::Document

def add_field(name, values, options = {})


document.add_field('title', 'A Title', :boost => 2.0)

=== Example:

See http://wiki.apache.org/solr/UpdateXmlMessages#head-8315b8028923d028950ff750a57ee22cbf7977c6
XML attributes in the Solr node.
Add a field value to the document. Options map directly to
def add_field(name, values, options = {})
  RSolr::Array.wrap(values).each do |v|
    field_attrs = { name: name }
    field_attrs[:type] = DocumentField if name.to_s == CHILD_DOCUMENT_KEY
    @fields << RSolr::Field.instance(options.merge(field_attrs), v)
  end
end

def as_json

def as_json
  @fields.group_by(&:name).each_with_object({}) do |(field, values), result|
    v = values.map(&:as_json)
    if v.length > 1 && v.first.is_a?(Hash)
      if v.first.key?(:value)
        v = v.first.merge(value: v.map { |single| single[:value] })
      else
        (v.first.keys & ATOMIC_MULTI_VALUE_OPERATIONS).each do |op|
          v = [{ op => v.map { |single| single[op] } }]
        end
      end
    end
    v = v.first if v.length == 1 && field.to_s != CHILD_DOCUMENT_KEY
    result[field] = v
  end
end

def field_by_name(name)

returns the *first* field that matches the "name" arg
def field_by_name(name)
  @fields.detect{|f|f.name==name}
end

def fields_by_name(name)

returns an array of fields that match the "name" arg
def fields_by_name(name)
  @fields.select{|f|f.name==name}
end

def initialize(doc_hash = {})

a field object is created for each value...
If a value in the "doc_hash" is an array,
"doc_hash" must be a Hash/Mash object
def initialize(doc_hash = {})
  @fields = []
  doc_hash.each_pair do |field, values|
    add_field(field, values)
  end
  @attrs={}
end