Class: Sunspot::Query::Sort
- Inherits:
-
Object
- Object
- Sunspot::Query::Sort
- Defined in:
- lib/sunspot/query/sort.rb
Overview
The Sort class is a query component representing a sort by a given field.
Constant Summary collapse
- DIRECTIONS =
:nodoc:
{ :asc => 'asc', :ascending => 'asc', :desc => 'desc', :descending => 'desc' }
Instance Method Summary collapse
-
#initialize(field, direction = nil) ⇒ Sort
constructor
A new instance of Sort.
- #to_param ⇒ Object
Constructor Details
#initialize(field, direction = nil) ⇒ Sort
Returns a new instance of Sort.
14 15 16 17 18 19 |
# File 'lib/sunspot/query/sort.rb', line 14 def initialize(field, direction = nil) if field.multiple? raise(ArgumentError, "#{field.name} cannot be used for ordering because it is a multiple-value field") end @field, @direction = field, (direction || :asc).to_sym end |
Instance Method Details
#to_param ⇒ Object
21 22 23 |
# File 'lib/sunspot/query/sort.rb', line 21 def to_param "#{@field.indexed_name.to_sym} #{direction_for_solr}" end |