Class: Sunspot::Setup
- Inherits:
-
Object
- Object
- Sunspot::Setup
- Defined in:
- lib/sunspot/setup.rb
Overview
This class encapsulates the search/indexing setup for a given class. Its contents are built using the Sunspot.setup method.
Class Method Summary collapse
-
.for(clazz) ⇒ Object
Retrieve the setup instance for the given class, or for the nearest ancestor that has a setup, if any.
-
.setup(clazz, &block) ⇒ Object
Retrieve or create the Setup instance for the given class, evaluating the given block to add to the setup’s configuration.
Instance Method Summary collapse
-
#add_dynamic_fields(fields) ⇒ Object
Add dynamic fields.
-
#add_fields(fields) ⇒ Object
Add fields for scope/ordering.
-
#add_text_fields(fields) ⇒ Object
Add fields for fulltext search.
-
#all_fields ⇒ Object
Get all static, dynamic, and text fields associated with this setup as well as all inherited fields.
-
#clazz ⇒ Object
Return the class associated with this setup.
-
#dynamic_fields ⇒ Object
Get all dynamic fields for this and parent setups.
-
#fields ⇒ Object
Get the fields associated with this setup as well as all inherited fields.
-
#indexer(connection) ⇒ Object
Factory method for an Indexer object configured to use this setup.
-
#initialize(clazz) ⇒ Setup
constructor
:nodoc:.
-
#setup(&block) ⇒ Object
Builder method for evaluating the setup DSL.
-
#text_fields ⇒ Object
Get the text fields associated with this setup as well as all inherited text fields.
Constructor Details
Class Method Details
.for(clazz) ⇒ Object
Retrieve the setup instance for the given class, or for the nearest ancestor that has a setup, if any.
Parameters
- clazz<Class>
-
Class for which to retrieve a setup
Returns
- Sunspot::Setup
-
Setup instance associated with the given class or its nearest ancestor
166 167 168 |
# File 'lib/sunspot/setup.rb', line 166 def for(clazz) #:nodoc: setups[clazz.name.to_sym] || self.for(clazz.superclass) if clazz end |
.setup(clazz, &block) ⇒ Object
Retrieve or create the Setup instance for the given class, evaluating the given block to add to the setup’s configuration
149 150 151 |
# File 'lib/sunspot/setup.rb', line 149 def setup(clazz, &block) #:nodoc: self.for!(clazz).setup(&block) end |
Instance Method Details
#add_dynamic_fields(fields) ⇒ Object
Add dynamic fields
Parameters
- fields<Array>
-
Array of dynamic field objects
42 43 44 |
# File 'lib/sunspot/setup.rb', line 42 def add_dynamic_fields(fields) @dynamic_fields.concat(Array(fields)) end |
#add_fields(fields) ⇒ Object
Add fields for scope/ordering
Parameters
- fields<Array>
-
Array of Sunspot::Field objects
20 21 22 |
# File 'lib/sunspot/setup.rb', line 20 def add_fields(fields) @fields.concat(Array(fields)) end |
#add_text_fields(fields) ⇒ Object
Add fields for fulltext search
Parameters
- fields<Array>
-
Array of Sunspot::Field objects
31 32 33 |
# File 'lib/sunspot/setup.rb', line 31 def add_text_fields(fields) @text_fields.concat(Array(fields)) end |
#all_fields ⇒ Object
Get all static, dynamic, and text fields associated with this setup as well as all inherited fields
Returns
- Array
-
Collection of all text and scope fields associated with this setup
84 85 86 87 88 |
# File 'lib/sunspot/setup.rb', line 84 def all_fields all_fields = [] all_fields.concat(fields).concat(text_fields).concat(dynamic_fields) all_fields end |
#clazz ⇒ Object
Return the class associated with this setup.
Returns
- clazz<Class>
-
Class setup is configured for
119 120 121 |
# File 'lib/sunspot/setup.rb', line 119 def clazz Util.full_const_get(@class_name) end |
#dynamic_fields ⇒ Object
Get all dynamic fields for this and parent setups
Returns
- Array
-
Dynamic fields
97 98 99 |
# File 'lib/sunspot/setup.rb', line 97 def dynamic_fields get_inheritable_collection(:dynamic_fields) end |
#fields ⇒ Object
Get the fields associated with this setup as well as all inherited fields
Returns
- Array
-
Collection of all fields associated with this setup
60 61 62 |
# File 'lib/sunspot/setup.rb', line 60 def fields get_inheritable_collection(:fields) end |
#indexer(connection) ⇒ Object
Factory method for an Indexer object configured to use this setup
Returns
- Sunspot::Indexer
-
Indexer configured with this setup
108 109 110 |
# File 'lib/sunspot/setup.rb', line 108 def indexer(connection) Indexer.new(connection, self) end |
#setup(&block) ⇒ Object
Builder method for evaluating the setup DSL
49 50 51 |
# File 'lib/sunspot/setup.rb', line 49 def setup(&block) @dsl.instance_eval(&block) end |
#text_fields ⇒ Object
Get the text fields associated with this setup as well as all inherited text fields
Returns
- Array
-
Collection of all text fields associated with this setup
72 73 74 |
# File 'lib/sunspot/setup.rb', line 72 def text_fields get_inheritable_collection(:text_fields) end |