Class: Sunspot::Query::BaseQuery
- Inherits:
-
Object
- Object
- Sunspot::Query::BaseQuery
- Includes:
- RSolr::Char
- Defined in:
- lib/sunspot/query/base_query.rb
Overview
Encapsulates information common to all queries - in particular, keywords and types.
Instance Attribute Summary collapse
-
#keywords ⇒ Object
writeonly
Sets the attribute keywords.
Instance Method Summary collapse
-
#initialize(types, setup) ⇒ BaseQuery
constructor
A new instance of BaseQuery.
-
#keyword_options=(options) ⇒ Object
Set keyword options.
-
#to_params ⇒ Object
Generate params for the base query.
Constructor Details
#initialize(types, setup) ⇒ BaseQuery
Returns a new instance of BaseQuery.
12 13 14 |
# File 'lib/sunspot/query/base_query.rb', line 12 def initialize(types, setup) @types, @setup = types, setup end |
Instance Attribute Details
#keywords=(value) ⇒ Object (writeonly)
Sets the attribute keywords
10 11 12 |
# File 'lib/sunspot/query/base_query.rb', line 10 def keywords=(value) @keywords = value end |
Instance Method Details
#keyword_options=(options) ⇒ Object
Set keyword options
39 40 41 42 43 |
# File 'lib/sunspot/query/base_query.rb', line 39 def () if @text_field_names = .delete(:fields) end end |
#to_params ⇒ Object
Generate params for the base query. If keywords are specified, build params for a dismax query, request all stored fields plus the score, and put the types in a filter query. If keywords are not specified, put the types query in the q parameter.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sunspot/query/base_query.rb', line 22 def to_params params = {} if @keywords params[:q] = @keywords params[:fl] = '* score' params[:fq] = types_phrase params[:qf] = text_field_names.join(' ') params[:defType] = 'dismax' else params[:q] = types_phrase end params end |