Class: Sunspot::Query::AbstractJsonFieldFacet
- Inherits:
-
Object
- Object
- Sunspot::Query::AbstractJsonFieldFacet
show all
- Defined in:
- lib/sunspot/query/abstract_json_field_facet.rb
Constant Summary
collapse
- DISTINCT_STRATEGIES =
[:unique, :hll]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AbstractJsonFieldFacet.
9
10
11
|
# File 'lib/sunspot/query/abstract_json_field_facet.rb', line 9
def initialize(field, options, setup)
@field, @options, @setup = field, options, setup
end
|
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
5
6
7
|
# File 'lib/sunspot/query/abstract_json_field_facet.rb', line 5
def field
@field
end
|
Instance Method Details
#get_params ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/sunspot/query/abstract_json_field_facet.rb', line 38
def get_params
query = field_name_with_local_params
nested_params = recursive_nested_params(@options)
if !nested_params.nil?
query[@field.name][:facet] ||= {}
query[@field.name][:facet].merge!(nested_params)
end
query
end
|
#init_params ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/sunspot/query/abstract_json_field_facet.rb', line 13
def init_params
params = {}
params[:limit] = @options[:limit] unless @options[:limit].nil?
params[:mincount] = @options[:minimum_count] unless @options[:minimum_count].nil?
params[:sort] = { @options[:sort] => @options[:sort_type]||'desc' } unless @options[:sort].nil?
params[:prefix] = @options[:prefix] unless @options[:prefix].nil?
params[:offset] = @options[:offset] unless @options[:offset].nil?
params[:allBuckets] = @options[:all_buckets] unless @options[:all_buckets].nil?
params[:missing] = @options[:missing] unless @options[:missing].nil?
params[:method] = @options[:method] unless @options[:method].nil?
if !@options[:distinct].nil?
dist_opts = @options[:distinct]
raise Exception.new("Need to specify a strategy") if dist_opts[:strategy].nil?
raise Exception.new("The strategy must be one of #{DISTINCT_STRATEGIES}") unless DISTINCT_STRATEGIES.include?(dist_opts[:strategy])
@stategy = dist_opts[:strategy]
@group_by = dist_opts[:group_by].nil? ? @field : @setup.field(dist_opts[:group_by])
params[:field] = @group_by.indexed_name
params[:facet] = {}
params[:facet][:distinct] = "#{@stategy}(#{@field.indexed_name})"
end
params
end
|
#to_params ⇒ Object
49
50
51
|
# File 'lib/sunspot/query/abstract_json_field_facet.rb', line 49
def to_params
{ 'json.facet' => self.get_params.to_json }
end
|