Class: Sunspot::Query::FieldStats

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

Instance Method Summary collapse

Constructor Details

#initialize(field, options) ⇒ FieldStats

Returns a new instance of FieldStats.



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

def initialize(field, options)
  @field, @options = field, options
  @facets = []
end

Instance Method Details

#add_facet(field) ⇒ Object



9
10
11
# File 'lib/sunspot/query/field_stats.rb', line 9

def add_facet field
  @facets << field
end

#facet_keyObject



19
20
21
# File 'lib/sunspot/query/field_stats.rb', line 19

def facet_key
  qualified_param 'facet'
end

#qualified_param(name) ⇒ Object



23
24
25
# File 'lib/sunspot/query/field_stats.rb', line 23

def qualified_param name
  :"f.#{@field.indexed_name}.stats.#{name}"
end

#to_paramsObject



13
14
15
16
17
# File 'lib/sunspot/query/field_stats.rb', line 13

def to_params
  params = { :stats => true, :"stats.field" => [@field.indexed_name]}
  params[facet_key] = @facets.map(&:indexed_name) unless @facets.empty?
  params
end