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, keywords and types.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute keywords to.



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 keyword_options=(options)
  if options
    @text_field_names = options.delete(:fields)
  end
end

#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.



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