Class: Sunspot::Query::BaseQuery

Inherits:
Object
  • Object
show all
Includes:
RSolr::Char
Defined in:
lib/sunspot/query/base_query.rb

Overview

Encapsulates information common to all queries - in particular, types. Subclassed by FulltextBaseQuery, which puts the types in a filter query and sets up dismax search.

Direct Known Subclasses

FulltextBaseQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types, setup) ⇒ BaseQuery

Returns a new instance of BaseQuery.



15
16
17
# File 'lib/sunspot/query/base_query.rb', line 15

def initialize(types, setup)
  @types, @setup = types, setup
end

Instance Attribute Details

#keywords=(value) ⇒ Object (writeonly)

Sets the attribute keywords

Parameters:

  • value

    the value to set the attribute keywords to.



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

def keywords=(value)
  @keywords = value
end

#phrase_fields=(value) ⇒ Object (writeonly)

Sets the attribute phrase_fields

Parameters:

  • value

    the value to set the attribute phrase_fields to.



13
14
15
# File 'lib/sunspot/query/base_query.rb', line 13

def phrase_fields=(value)
  @phrase_fields = value
end

#typesObject (readonly)

Returns the value of attribute types.



11
12
13
# File 'lib/sunspot/query/base_query.rb', line 11

def types
  @types
end

Instance Method Details

#to_paramsObject

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.



25
26
27
# File 'lib/sunspot/query/base_query.rb', line 25

def to_params
  { :q => types_phrase }
end