Class: Sunspot::Query::FieldGroup
- Inherits:
-
Object
- Object
- Sunspot::Query::FieldGroup
- Defined in:
- lib/sunspot/query/field_group.rb
Overview
A FieldGroup groups by the unique values of a given field.
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#truncate ⇒ Object
Returns the value of attribute truncate.
Instance Method Summary collapse
- #add_sort(sort) ⇒ Object
-
#initialize(field) ⇒ FieldGroup
constructor
A new instance of FieldGroup.
- #to_params ⇒ Object
Constructor Details
#initialize(field) ⇒ FieldGroup
Returns a new instance of FieldGroup.
9 10 11 12 13 14 15 16 |
# File 'lib/sunspot/query/field_group.rb', line 9 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 |
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
7 8 9 |
# File 'lib/sunspot/query/field_group.rb', line 7 def limit @limit end |
#truncate ⇒ Object
Returns the value of attribute truncate.
7 8 9 |
# File 'lib/sunspot/query/field_group.rb', line 7 def truncate @truncate end |
Instance Method Details
#add_sort(sort) ⇒ Object
18 19 20 |
# File 'lib/sunspot/query/field_group.rb', line 18 def add_sort(sort) @sort << sort end |
#to_params ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sunspot/query/field_group.rb', line 22 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 |