Class: Sunspot::FieldFactory::Static
- Defined in:
- lib/sunspot/field_factory.rb
Overview
A StaticFieldFactory generates normal static fields. Each factory instance contains an eager-initialized field instance, which is returned by the #build method.
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#build ⇒ Object
Return the field instance built by this factory.
-
#initialize(name, type, options = {}, &block) ⇒ Static
constructor
A new instance of Static.
-
#populate_document(document, model) ⇒ Object
Extract the encapsulated field’s data from the given model and add it into the RSolr document for indexing.
-
#signature ⇒ Object
A unique signature identifying this field by name and type.
Constructor Details
#initialize(name, type, options = {}, &block) ⇒ Static
Returns a new instance of Static.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sunspot/field_factory.rb', line 33 def initialize(name, type, = {}, &block) super(name, , &block) unless name.to_s =~ /^\w+$/ raise ArgumentError, "Invalid field name #{name}: only letters, numbers, and underscores are allowed." end @field = if type == Type::TextType FulltextField.new(name, ) else AttributeField.new(name, type, ) end end |
Instance Method Details
#build ⇒ Object
Return the field instance built by this factory
49 50 51 |
# File 'lib/sunspot/field_factory.rb', line 49 def build @field end |
#populate_document(document, model) ⇒ Object
Extract the encapsulated field’s data from the given model and add it into the RSolr document for indexing.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sunspot/field_factory.rb', line 57 def populate_document(document, model) #:nodoc: unless (value = @data_extractor.value_for(model)).nil? Util.Array(@field.to_indexed(value)).each do |scalar_value| document.add_field( @field.indexed_name.to_sym, scalar_value, @field.attributes ) end end end |
#signature ⇒ Object
A unique signature identifying this field by name and type.
71 72 73 |
# File 'lib/sunspot/field_factory.rb', line 71 def signature [@field.name, @field.type] end |