Class: Sunspot::Query::Connective::Abstract
- Defined in:
- lib/sunspot/query/connective.rb
Overview
Base class for connectives (conjunctions and disjunctions).
Direct Known Subclasses
Instance Method Summary collapse
-
#add_component(component) ⇒ Object
Add a component to the connective.
-
#initialize(setup) ⇒ Abstract
constructor
:nodoc:.
-
#to_boolean_phrase ⇒ Object
Express the connective as a Lucene boolean phrase.
-
#to_params ⇒ Object
Connective as solr params.
Methods inherited from Scope
#add_conjunction, #add_disjunction, #add_negated_restriction, #add_negated_shorthand_restriction, #add_restriction, #add_shorthand_restriction, #dynamic_query, #exclude_instance
Constructor Details
#initialize(setup) ⇒ Abstract
:nodoc:
8 9 10 11 |
# File 'lib/sunspot/query/connective.rb', line 8 def initialize(setup) #:nodoc: @setup = setup @components = [] end |
Instance Method Details
#add_component(component) ⇒ Object
Add a component to the connective. All components must implement the #to_boolean_phrase method.
38 39 40 |
# File 'lib/sunspot/query/connective.rb', line 38 def add_component(component) #:nodoc: @components << component end |
#to_boolean_phrase ⇒ Object
Express the connective as a Lucene boolean phrase.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sunspot/query/connective.rb', line 23 def to_boolean_phrase #:nodoc: if @components.length == 1 @components.first.to_boolean_phrase else component_phrases = @components.map do |component| component.to_boolean_phrase end "(#{component_phrases.join(" #{connector} ")})" end end |
#to_params ⇒ Object
Connective as solr params.
16 17 18 |
# File 'lib/sunspot/query/connective.rb', line 16 def to_params #:nodoc: { :fq => to_boolean_phrase } end |