Class: Sunspot::DSL::FieldGroup
- Inherits:
-
Object
- Object
- Sunspot::DSL::FieldGroup
- Defined in:
- lib/sunspot/dsl/field_group.rb
Instance Method Summary collapse
-
#initialize(setup, group) ⇒ FieldGroup
constructor
A new instance of FieldGroup.
-
#limit(num) ⇒ Object
Sets the number of results (documents) to return for each group.
-
#order_by(field_name, direction = nil) ⇒ Object
Specify the order that results should be returned in.
-
#truncate ⇒ Object
If set, facet counts are based on the most relevant document of each group matching the query.
Constructor Details
#initialize(setup, group) ⇒ FieldGroup
Returns a new instance of FieldGroup.
4 5 6 |
# File 'lib/sunspot/dsl/field_group.rb', line 4 def initialize(setup, group) @setup, @group = setup, group end |
Instance Method Details
#limit(num) ⇒ Object
Sets the number of results (documents) to return for each group. Defaults to 1.
12 13 14 |
# File 'lib/sunspot/dsl/field_group.rb', line 12 def limit(num) @group.limit = num end |
#order_by(field_name, direction = nil) ⇒ Object
Specify the order that results should be returned in. This method can be called multiple times; precedence will be in the order given.
Parameters
- field_name<Symbol>
-
the field to use for ordering
- direction<Symbol>
-
:asc or :desc (default :asc)
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sunspot/dsl/field_group.rb', line 44 def order_by(field_name, direction = nil) sort = if special = Sunspot::Query::Sort.special(field_name) special.new(direction) else Sunspot::Query::Sort::FieldSort.new( @setup.field(field_name), direction ) end @group.add_sort(sort) end |
#truncate ⇒ Object
32 33 34 |
# File 'lib/sunspot/dsl/field_group.rb', line 32 def truncate @group.truncate = true end |