class RSolr::Message::Document

A class that represents a “doc” xml element for a solr update

def add_field(name, value, 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, value, options = {})
  @fields << Field.new(options.merge({:name=>name}), value)
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|
    # create a new field for each value (multi-valued)
    # put non-array values into an array
    values = [values] unless values.is_a?(Array)
    values.each do |v|
      next if v.to_s.empty?
      @fields << Field.new({:name=>field}, v)
    end
  end
  @attrs={}
end