Class: Sunspot::FieldFactory::Dynamic
- Inherits:
-
Abstract
- Object
- Abstract
- Sunspot::FieldFactory::Dynamic
- Defined in:
- sunspot/lib/sunspot/field_factory.rb
Overview
DynamicFieldFactories create dynamic field instances based on dynamic configuration.
Instance Attribute Summary (collapse)
-
- (Object) name
Returns the value of attribute name.
-
- (Object) type
Returns the value of attribute type.
Attributes inherited from Abstract
Instance Method Summary (collapse)
-
- (Object) build(dynamic_name)
(also: #field)
Build a field based on the dynamic name given.
-
- (Dynamic) initialize(name, type, options = {}, &block)
constructor
A new instance of Dynamic.
-
- (Object) populate_document(document, model)
Generate dynamic fields based on hash returned by data accessor and add the field data to the document.
-
- (Object) signature
Unique signature identifying this dynamic field based on name and type.
Constructor Details
- (Dynamic) initialize(name, type, options = {}, &block)
A new instance of Dynamic
86 87 88 89 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 86 def initialize(name, type, = {}, &block) super(name, , &block) @type, @options = type, end |
Instance Attribute Details
- (Object) name
Returns the value of attribute name
84 85 86 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 84 def name @name end |
- (Object) type
Returns the value of attribute type
84 85 86 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 84 def type @type end |
Instance Method Details
- (Object) build(dynamic_name) Also known as: field
Build a field based on the dynamic name given.
94 95 96 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 94 def build(dynamic_name) AttributeField.new("#{@name}:#{dynamic_name}", @type, @options.dup) end |
- (Object) populate_document(document, model)
Generate dynamic fields based on hash returned by data accessor and add the field data to the document.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 107 def populate_document(document, model) if values = @data_extractor.value_for(model) values.each_pair do |dynamic_name, value| field_instance = build(dynamic_name) Util.Array(field_instance.to_indexed(value)).each do |scalar_value| document.add_field( field_instance.indexed_name.to_sym, scalar_value ) end end end end |
- (Object) signature
Unique signature identifying this dynamic field based on name and type
124 125 126 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 124 def signature [@name, @type] end |