Class: Sunspot::Query::AbstractFieldFacet

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/query/abstract_field_facet.rb

Direct Known Subclasses

DateFieldFacet, FieldFacet

Instance Method Summary collapse

Constructor Details

#initialize(field, options) ⇒ AbstractFieldFacet

Returns a new instance of AbstractFieldFacet.



4
5
6
# File 'lib/sunspot/query/abstract_field_facet.rb', line 4

def initialize(field, options)
  @field, @options = field, options
end

Instance Method Details

#to_paramsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sunspot/query/abstract_field_facet.rb', line 8

def to_params
  params = {
    :facet => 'true',
  }
  case @options[:sort]
  when :count
    params[qualified_param('sort')] = 'true'
  when :index
    params[qualified_param('sort')] = 'false'
  when nil
  else
    raise(
      ArgumentError,
      "#{@options[:sort].inspect} is not an allowed value for :sort. Allowed options are :count and :index"
    )
  end
  if @options[:limit]
    params[qualified_param('limit')] = @options[:limit].to_i
  end
  params[qualified_param('mincount')] = 
    case
    when @options[:minimum_count] then @options[:minimum_count].to_i
    when @options[:zeros] then 0
    else 1
    end
  params
end