Class: Sunspot::FieldFactory::Static
- Inherits:
-
Abstract
- Object
- Abstract
- Sunspot::FieldFactory::Static
- Defined in:
- sunspot/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)
-
- (Object) build
Return the field instance built by this factory.
-
- (Static) initialize(name, type, options = {}, &block)
constructor
A new instance of Static.
-
- (Object) populate_document(document, model)
Extract the encapsulated field’s data from the given model and add it into the Solr document for indexing.
-
- (Object) signature
A unique signature identifying this field by name and type.
Constructor Details
- (Static) initialize(name, type, options = {}, &block)
A new instance of Static
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'sunspot/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.is_a?(Type::TextType) FulltextField.new(name, ) else AttributeField.new(name, type, ) end end |
Instance Method Details
- (Object) build
Return the field instance built by this factory
49 50 51 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 49 def build @field end |
- (Object) populate_document(document, model)
Extract the encapsulated field’s data from the given model and add it into the Solr document for indexing.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'sunspot/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| = {} [:boost] = @field.boost if @field.boost document.add_field( @field.indexed_name.to_sym, scalar_value, ) end end end |
- (Object) signature
A unique signature identifying this field by name and type.
74 75 76 |
# File 'sunspot/lib/sunspot/field_factory.rb', line 74 def signature [@field.name, @field.type] end |