Class: Sunspot::CompositeSetup
- Inherits:
-
Object
- Object
- Sunspot::CompositeSetup
- Defined in:
- sunspot/lib/sunspot/composite_setup.rb
Overview
The CompositeSetup class encapsulates a collection of setups, and responds to a subset of the methods that Setup responds to (in particular, the methods required to build queries).
Instance Method Summary (collapse)
- - (Object) all_more_like_this_fields
-
- (Object) all_text_fields
Collection of all text fields configured for any of the enclosed types.
-
- (Object) dynamic_field_factory(field_name)
Get a dynamic field factory for the given base name.
-
- (Object) field(field_name)
Get a Sunspot::AttributeField instance corresponding to the given field name.
-
- (CompositeSetup) initialize(types)
constructor
A new instance of CompositeSetup.
-
- (Object) setups
Collection of Setup objects for the enclosed types.
-
- (Object) text_fields(field_name)
Get a text field object by its public name.
-
- (Object) type_names
Return the names of the encapsulated types.
Constructor Details
- (CompositeSetup) initialize(types)
A new instance of CompositeSetup
12 13 14 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 12 def initialize(types) @types = types end |
Instance Method Details
- (Object) all_more_like_this_fields
115 116 117 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 115 def all_more_like_this_fields @more_like_this_fields ||= more_like_this_fields_hash.values.map { |set| set.to_a }.flatten end |
- (Object) all_text_fields
Collection of all text fields configured for any of the enclosed types.
Returns
Array | Text fields configured for the enclosed types |
111 112 113 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 111 def all_text_fields @text_fields ||= text_fields_hash.values.map { |set| set.to_a }.flatten end |
- (Object) dynamic_field_factory(field_name)
Get a dynamic field factory for the given base name.
Returns
DynamicFieldFactory | Factory for dynamic fields with the given base name |
Raises
UnrecognizedFieldError | If the given base name is not configured as a dynamic field for the types being queried |
97 98 99 100 101 102 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 97 def dynamic_field_factory(field_name) dynamic_field_factories_hash[field_name.to_sym] || raise( UnrecognizedFieldError, "No dynamic field configured for #{@types * ', '} with name #{field_name.inspect}" ) end |
- (Object) field(field_name)
Get a Sunspot::AttributeField instance corresponding to the given field name
Parameters
field_name | The public field name for which to find a field |
Returns
Sunspot::AttributeField The field object corresponding to the given name
Raises
ArgumentError | If the given field name is not configured for the types being queried |
78 79 80 81 82 83 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 78 def field(field_name) #:nodoc: fields_hash[field_name.to_sym] || raise( UnrecognizedFieldError, "No field configured for #{@types * ', '} with name '#{field_name}'" ) end |
- (Object) setups
Collection of Setup objects for the enclosed types
Returns
Array | Collection of Setup objects |
23 24 25 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 23 def setups @setups ||= @types.map { |type| Setup.for(type) } end |
- (Object) text_fields(field_name)
Get a text field object by its public name. A field will be returned if it is configured for any of the enclosed types.
Returns
Sunspot::FulltextField | Text field with the given public name |
Raises
UnrecognizedFieldError | If no field with that name is configured for any of the enclosed types. |
51 52 53 54 55 56 57 58 59 60 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 51 def text_fields(field_name) if text_fields = text_fields_hash[field_name.to_sym] text_fields.to_a else raise( UnrecognizedFieldError, "No text field configured for #{@types * ', '} with name '#{field_name}'" ) end end |
- (Object) type_names
Return the names of the encapsulated types
Returns
Array | Collection of class names |
34 35 36 |
# File 'sunspot/lib/sunspot/composite_setup.rb', line 34 def type_names @type_names ||= @types.map { |clazz| clazz.name } end |