Class: RSolr::Message::Document
- Inherits:
-
Object
- Object
- RSolr::Message::Document
- Defined in:
- lib/rsolr/message.rb
Overview
A class that represents a “doc” xml element for a solr update
Instance Attribute Summary collapse
-
#attrs ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “fields” is an array of Field objects.
-
#fields ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “fields” is an array of Field objects.
Instance Method Summary collapse
-
#field_by_name(name) ⇒ Object
returns the first field that matches the “name” arg.
-
#fields_by_name(name) ⇒ Object
returns an array of fields that match the “name” arg.
-
#initialize(doc_hash) ⇒ Document
constructor
“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…
Constructor Details
#initialize(doc_hash) ⇒ Document
“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…
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rsolr/message.rb', line 19 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 |
Instance Attribute Details
#attrs ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “fields” is an array of Field objects
14 15 16 |
# File 'lib/rsolr/message.rb', line 14 def attrs @attrs end |
#fields ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “fields” is an array of Field objects
14 15 16 |
# File 'lib/rsolr/message.rb', line 14 def fields @fields end |
Instance Method Details
#field_by_name(name) ⇒ Object
returns the first field that matches the “name” arg
39 40 41 |
# File 'lib/rsolr/message.rb', line 39 def field_by_name(name) @fields.detect{|f|f.name==name} end |
#fields_by_name(name) ⇒ Object
returns an array of fields that match the “name” arg
34 35 36 |
# File 'lib/rsolr/message.rb', line 34 def fields_by_name(name) @fields.select{|f|f.name==name} end |