Class: Solr::Document
- Inherits:
-
Object
- Object
- Solr::Document
- Includes:
- Enumerable
- Defined in:
- lib/solr/document.rb
Overview
The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Instance Attribute Summary collapse
-
#boost ⇒ Object
Returns the value of attribute boost.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
-
#<<(fields) ⇒ Object
Append a Solr::Field.
-
#[](name) ⇒ Object
shorthand to allow hash lookups doc.
-
#[]=(name, value) ⇒ Object
shorthand to assign as a hash.
- #each(*args, &blk) ⇒ Object
-
#initialize(hash = {}) ⇒ Document
constructor
Create a new Solr::Document, optionally passing in a hash of key/value pairs for the fields.
-
#to_xml ⇒ Object
convert the Document to a REXML::Element.
Constructor Details
Instance Attribute Details
#boost ⇒ Object
Returns the value of attribute boost.
15 16 17 |
# File 'lib/solr/document.rb', line 15 def boost @boost end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
16 17 18 |
# File 'lib/solr/document.rb', line 16 def fields @fields end |
Instance Method Details
#<<(fields) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/solr/document.rb', line 34 def <<(fields) case fields when Hash fields.each_pair do |name,value| if value.respond_to?(:each) && !value.is_a?(String) value.each {|v| @fields << Solr::Field.new(name => v)} else @fields << Solr::Field.new(name => value) end end when Solr::Field @fields << fields else raise "must pass in Solr::Field or Hash" end end |
#[](name) ⇒ Object
shorthand to allow hash lookups
doc['name']
53 54 55 56 57 |
# File 'lib/solr/document.rb', line 53 def [](name) field = @fields.find {|f| f.name == name.to_s} return field.value if field return nil end |
#[]=(name, value) ⇒ Object
shorthand to assign as a hash
60 61 62 |
# File 'lib/solr/document.rb', line 60 def []=(name,value) @fields << Solr::Field.new(name => value) end |
#each(*args, &blk) ⇒ Object
72 73 74 |
# File 'lib/solr/document.rb', line 72 def each(*args, &blk) fields.each(&blk) end |