Class: Sunspot::CompositeSetup

Inherits:
Object
  • Object
show all
Defined in:
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

Constructor Details

#initialize(types) ⇒ CompositeSetup

Returns a new instance of CompositeSetup.



12
13
14
# File 'lib/sunspot/composite_setup.rb', line 12

def initialize(types)
  @types = types
end

Instance Method Details

#all_more_like_this_fieldsObject



115
116
117
# File '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

#all_text_fieldsObject

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 'lib/sunspot/composite_setup.rb', line 111

def all_text_fields
  @text_fields ||= text_fields_hash.values.map { |set| set.to_a }.flatten
end

#dynamic_field_factory(field_name) ⇒ Object

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 '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

#field(field_name) ⇒ Object

Get a Sunspot::AttributeField instance corresponding to the given field name

Parameters

field_name<Symbol>

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 '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

#setupsObject

Collection of Setup objects for the enclosed types

Returns

Array

Collection of Setup objects



23
24
25
# File 'lib/sunspot/composite_setup.rb', line 23

def setups
  @setups ||= @types.map { |type| Setup.for(type) }
end

#text_fields(field_name) ⇒ Object

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 '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

#type_namesObject

Return the names of the encapsulated types

Returns

Array

Collection of class names



34
35
36
# File 'lib/sunspot/composite_setup.rb', line 34

def type_names
  @type_names ||= @types.map { |clazz| clazz.name }
end