Sha256: 8b5ac766978cd59529da9b241b68322d41d6e3dcbb6e66f333cc096cf357bdef

Contents?: true

Size: 741 Bytes

Versions: 1

Compression:

Stored size: 741 Bytes

Contents

module Sunspot
  module Query
    #
    # A FieldGroup groups by the unique values of a given field.
    #
    class FieldGroup
      attr_accessor :limit

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

        @sort = SortComposite.new
      end

      def add_sort(sort)
        @sort << sort
      end

      def to_params
        params = {
          :group         => "true",
          :"group.field" => @field.indexed_name,
        }

        params.merge!(@sort.to_params("group."))
        params[:"group.limit"] = @limit if @limit

        params
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunspot-2.0.0.pre.111215 lib/sunspot/query/field_group.rb