Class: Sunspot::Query::SortComposite
- Inherits:
-
Object
- Object
- Sunspot::Query::SortComposite
- Defined in:
- sunspot/lib/sunspot/query/sort_composite.rb
Overview
The SortComposite class encapsulates an ordered collection of Sort objects. It’s necessary to keep this as a separate class as Solr takes the sort as a single parameter, so adding sorts as regular components would not merge correctly in the #to_params method.
Instance Method Summary (collapse)
-
- (Object) <<(sort)
Add a sort to the composite.
-
- (SortComposite) initialize
constructor
:nodoc:.
-
- (Object) to_params
Combine the sorts into a single param by joining them.
Constructor Details
- (SortComposite) initialize
:nodoc:
10 11 12 |
# File 'sunspot/lib/sunspot/query/sort_composite.rb', line 10 def initialize @sorts = [] end |
Instance Method Details
- (Object) <<(sort)
Add a sort to the composite
17 18 19 |
# File 'sunspot/lib/sunspot/query/sort_composite.rb', line 17 def <<(sort) @sorts << sort end |
- (Object) to_params
Combine the sorts into a single param by joining them
24 25 26 27 28 29 30 |
# File 'sunspot/lib/sunspot/query/sort_composite.rb', line 24 def to_params unless @sorts.empty? { :sort => @sorts.map { |sort| sort.to_param } * ', ' } else {} end end |