Class: Sunspot::Query::FieldStat

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

Overview

A FieldStat stats by the unique values of a given field.

Instance Method Summary collapse

Constructor Details

#initialize(field, options = {}) ⇒ FieldStat

Returns a new instance of FieldStat.



8
9
10
11
12
13
14
15
# File 'lib/query/field_stat.rb', line 8

def initialize(field, options = {})
  if field.multiple?
    raise(ArgumentError, "#{field.name} cannot be used for stats because it is a multiple-value field")
  end
  @field = field
  @options = options
  @sort = SortComposite.new
end

Instance Method Details

#add_sort(sort) ⇒ Object



17
18
19
# File 'lib/query/field_stat.rb', line 17

def add_sort(sort)
  @sort << sort
end

#to_paramsObject



21
22
23
24
25
26
27
28
# File 'lib/query/field_stat.rb', line 21

def to_params
  params = {
    :stats  => 'true',
    :"stats.field" => @field.indexed_name
  }
  params.merge!({:"stats.facet" => @options[:facet].indexed_name}) if !@options[:facet].nil?
  params
end