Class: Sunspot::Query::Group
- Inherits:
-
Object
- Object
- Sunspot::Query::Group
- Defined in:
- lib/sunspot/query/group.rb
Overview
A Group groups by the unique values of a given field, or by given queries.
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#ngroups ⇒ Object
Returns the value of attribute ngroups.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
-
#truncate ⇒ Object
Returns the value of attribute truncate.
Instance Method Summary collapse
- #add_field(field) ⇒ Object
- #add_query(query) ⇒ Object
- #add_sort(sort) ⇒ Object
-
#initialize ⇒ Group
constructor
A new instance of Group.
- #to_params ⇒ Object
Constructor Details
#initialize ⇒ Group
Returns a new instance of Group.
10 11 12 13 14 |
# File 'lib/sunspot/query/group.rb', line 10 def initialize @sort = SortComposite.new @fields = [] @queries = [] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
8 9 10 |
# File 'lib/sunspot/query/group.rb', line 8 def fields @fields end |
#limit ⇒ Object
Returns the value of attribute limit.
7 8 9 |
# File 'lib/sunspot/query/group.rb', line 7 def limit @limit end |
#ngroups ⇒ Object
Returns the value of attribute ngroups.
7 8 9 |
# File 'lib/sunspot/query/group.rb', line 7 def ngroups @ngroups end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
8 9 10 |
# File 'lib/sunspot/query/group.rb', line 8 def queries @queries end |
#truncate ⇒ Object
Returns the value of attribute truncate.
7 8 9 |
# File 'lib/sunspot/query/group.rb', line 7 def truncate @truncate end |
Instance Method Details
#add_field(field) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/sunspot/query/group.rb', line 16 def add_field(field) if field.multiple? raise(ArgumentError, "#{field.name} cannot be used for grouping because it is a multiple-value field") end @fields << field end |
#add_query(query) ⇒ Object
23 24 25 |
# File 'lib/sunspot/query/group.rb', line 23 def add_query(query) @queries << query end |
#add_sort(sort) ⇒ Object
27 28 29 |
# File 'lib/sunspot/query/group.rb', line 27 def add_sort(sort) @sort << sort end |
#to_params ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sunspot/query/group.rb', line 31 def to_params params = { :group => 'true', :"group.ngroups" => @ngroups.nil? ? 'true' : @ngroups.to_s } params.merge!(@sort.to_params('group.')) params[:"group.field"] = @fields.map(&:indexed_name) if @fields.any? params[:"group.query"] = @queries.map(&:to_boolean_phrase) if @queries.any? params[:"group.limit"] = @limit if @limit params[:"group.truncate"] = @truncate if @truncate params end |