Class: Solr::Indexing::Document

Inherits:
Object
  • Object
show all
Includes:
Support::SchemaHelper
Defined in:
lib/solr/indexing/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::SchemaHelper

#solarize_field

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

#fieldsObject (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