Class: Solr::Indexing::Document
- Inherits:
-
Object
- Object
- Solr::Indexing::Document
- Includes:
- Support::SchemaHelper
- Defined in:
- lib/solr/indexing/document.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #add_field(name, value) ⇒ Object
-
#initialize(fields = {}) ⇒ Document
constructor
A new instance of Document.
-
#to_json(_json_context) ⇒ Object
TODO: refactor & optimize this.
Methods included from Support::SchemaHelper
Constructor Details
#initialize(fields = {}) ⇒ Document
Returns a new instance of Document.
7 8 9 |
# File 'lib/solr/indexing/document.rb', line 7 def initialize(fields = {}) @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
5 6 7 |
# File 'lib/solr/indexing/document.rb', line 5 def fields @fields end |
Instance Method Details
#add_field(name, value) ⇒ Object
11 12 13 |
# File 'lib/solr/indexing/document.rb', line 11 def add_field(name, value) @fields[name] = value end |
#to_json(_json_context) ⇒ Object
TODO: refactor & optimize this
16 17 18 19 20 21 22 |
# File 'lib/solr/indexing/document.rb', line 16 def to_json(_json_context) solr_fields = fields.map do |k, v| solr_field_name = solarize_field(k) [solr_field_name, v] end.to_h JSON.generate(solr_fields) end |