Class: Sunspot::Query::Sort

Inherits:
Object
  • Object
show all
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

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_paramObject



21
22
23
# File 'lib/sunspot/query/sort.rb', line 21

def to_param
  "#{@field.indexed_name.to_sym} #{direction_for_solr}"
end