Sha256: 5a310d09dc47cdd3bbbd4a4c259eed1a280cc6fede092a696584003a40499800

Contents?: true

Size: 740 Bytes

Versions: 3

Compression:

Stored size: 740 Bytes

Contents

module Sunspot
  module Query
    #
    # A FieldStat stats by the unique values of a given field.
    #
    class FieldStat

      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

      def add_sort(sort)
        @sort << sort
      end

      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sunspot_stats-0.0.5 lib/query/field_stat.rb
sunspot_stats-0.0.4 lib/query/field_stat.rb
sunspot_stats-0.0.3 lib/query/field_stat.rb