class RSolr::Xml::Document
Attributes
attrs[RW]
“attrs” is a hash for setting the “doc” xml attributes “fields” is an array of Field objects
fields[RW]
“attrs” is a hash for setting the “doc” xml attributes “fields” is an array of Field objects
Public Class Methods
new(doc_hash = {})
click to toggle source
“doc_hash” must be a Hash/Mash object If a value in the “doc_hash” is an array, a field object is created for each value…
# File lib/rsolr/xml.rb, line 15 def initialize(doc_hash = {}) @fields = [] doc_hash.each_pair do |field,values| # create a new field for each value (multi-valued) wrap(values).each do |v| v = format_value(v) next if v.empty? @fields << RSolr::Xml::Field.new({:name=>field}, v) end end @attrs={} end
Public Instance Methods
add_field(name, value, options = {})
click to toggle source
Add a field value to the document. Options map directly to XML attributes in the Solr <field> node. See wiki.apache.org/solr/UpdateXmlMessages#head-8315b8028923d028950ff750a57ee22cbf7977c6
Example:¶ ↑
document.add_field('title', 'A Title', :boost => 2.0)
# File lib/rsolr/xml.rb, line 47 def add_field(name, value, options = {}) @fields << RSolr::Xml::Field.new(options.merge({:name=>name}), value) end
field_by_name(name)
click to toggle source
returns the first field that matches the “name” arg
# File lib/rsolr/xml.rb, line 34 def field_by_name(name) @fields.detect{|f|f.name==name} end
fields_by_name(name)
click to toggle source
returns an array of fields that match the “name” arg
# File lib/rsolr/xml.rb, line 29 def fields_by_name(name) @fields.select{|f|f.name==name} end
Private Instance Methods
format_value(v)
click to toggle source
# File lib/rsolr/xml.rb, line 53 def format_value(v) case v when Time v.getutc.iso8601 when DateTime v.to_time.getutc.iso8601 when Date Time.utc(v.year, v.mon, v.mday).iso8601 else v.to_s end end
wrap(object)
click to toggle source
# File lib/rsolr/xml.rb, line 66 def wrap(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary || [object] elsif object.is_a? Enumerable object else [object] end end