Sha256: d022f529d725c6beb079663bc5fffc318c75e2ba7084570d807fe1dabcb81d29

Contents?: true

Size: 855 Bytes

Versions: 12

Compression:

Stored size: 855 Bytes

Contents

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

      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.ngroups"  => "true",
          :"group.field"    => @field.indexed_name
        }

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

        params
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
sunspot-2.2.0 lib/sunspot/query/field_group.rb
sunspot-2.1.1 lib/sunspot/query/field_group.rb
sunspot-2.1.0 lib/sunspot/query/field_group.rb
sunspot-2.0.0 lib/sunspot/query/field_group.rb
sunspot-2.0.0.pre.130115 lib/sunspot/query/field_group.rb
sunspot-2.0.0.pre.120925 lib/sunspot/query/field_group.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/query/field_group.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/query/field_group.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/query/field_group.rb
sunspot-2.0.0.pre.120720 lib/sunspot/query/field_group.rb
sunspot-2.0.0.pre.120417 lib/sunspot/query/field_group.rb
sunspot-2.0.0.pre.120415 lib/sunspot/query/field_group.rb