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, options = {}) ⇒ Object
Extract the encapsulated field’s data from the given model and add it into the Solr 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.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sunspot/field_factory.rb', line 50 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
#build ⇒ Object
Return the field instance built by this factory
66 67 68 |
# File 'lib/sunspot/field_factory.rb', line 66 def build @field end |
#populate_document(document, model, options = {}) ⇒ Object
Extract the encapsulated field’s data from the given model and add it into the Solr document for indexing.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sunspot/field_factory.rb', line 74 def populate_document(document, model, = {}) #:nodoc: atomic_operation = [:update] == :set value = extract_value(model, ) if value != nil || atomic_operation indexed_values = Util.Array(@field.to_indexed(value)) indexed_values = [nil] if indexed_values.empty? && atomic_operation indexed_values.each do |scalar_value| = {} [:boost] = @field.boost if @field.boost [:null] = true if scalar_value.nil? && atomic_operation document.add_field( @field.indexed_name.to_sym, scalar_value, .merge() ) end end end |
#signature ⇒ Object
A unique signature identifying this field by name and type.
96 97 98 |
# File 'lib/sunspot/field_factory.rb', line 96 def signature [@field.name, @field.type] end |