Class: Sunspot::Query::FulltextBaseQuery
- Inherits:
-
BaseQuery
- Object
- BaseQuery
- Sunspot::Query::FulltextBaseQuery
show all
- Defined in:
- lib/sunspot/query/fulltext_base_query.rb
Overview
Instance Attribute Summary
Attributes inherited from BaseQuery
#keywords, #phrase_fields, #types
Instance Method Summary
collapse
Constructor Details
#initialize(keywords, options, types, setup) ⇒ FulltextBaseQuery
Returns a new instance of FulltextBaseQuery.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/sunspot/query/fulltext_base_query.rb', line 4
def initialize(keywords, options, types, setup)
super(types, setup)
@keywords = keywords
if highlight_options = options.delete(:highlight)
set_highlight(highlight_options == true ? [] : highlight_options)
end
if fulltext_fields = options.delete(:fields)
Array(fulltext_fields).each do |field|
add_fulltext_field(field)
end
end
end
|
Instance Method Details
#add_fulltext_field(field_name, boost = nil) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/sunspot/query/fulltext_base_query.rb', line 37
def add_fulltext_field(field_name, boost = nil)
@fulltext_fields ||= []
@fulltext_fields.concat(
@setup.text_fields(field_name).map do |field|
TextFieldBoost.new(field, boost)
end
)
end
|
#add_phrase_field(field_name, boost = nil) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/sunspot/query/fulltext_base_query.rb', line 46
def add_phrase_field(field_name, boost = nil)
@phrase_fields ||= []
@phrase_fields.concat(
@setup.text_fields(field_name).map do |field|
TextFieldBoost.new(field, boost)
end
)
end
|
#create_boost_query(factor) ⇒ Object
55
56
57
|
# File 'lib/sunspot/query/fulltext_base_query.rb', line 55
def create_boost_query(factor)
@boost_query ||= BoostQuery.new(factor, @setup)
end
|
#set_highlight(field_names = [], options = {}) ⇒ Object
59
60
61
|
# File 'lib/sunspot/query/fulltext_base_query.rb', line 59
def set_highlight(field_names=[], options={})
@highlight = Highlighting.new(text_fields(field_names), options)
end
|
#to_params ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sunspot/query/fulltext_base_query.rb', line 19
def to_params
params = { :q => @keywords }
params[:fl] = '* score'
params[:fq] = types_phrase
params[:qf] = query_fields
params[:defType] = 'dismax'
if @phrase_fields
params[:pf] = @phrase_fields.map { |field| field.to_boosted_field }.join(' ')
end
if @boost_query
params[:bq] = @boost_query.to_boolean_phrase
end
if @highlight
Sunspot::Util.deep_merge!(params, @highlight.to_params)
end
params
end
|