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

ASCENDING =

:nodoc:

Set.new([:asc, :ascending])
DESCENDING =
Set.new([:desc, :descending])

Instance Method Summary collapse

Constructor Details

#initialize(field, direction = nil) ⇒ Sort

Returns a new instance of Sort.



10
11
12
# File 'lib/sunspot/query/sort.rb', line 10

def initialize(field, direction = nil)
  @field, @direction = field, (direction || :asc).to_sym
end

Instance Method Details

#to_paramsObject



14
15
16
# File 'lib/sunspot/query/sort.rb', line 14

def to_params
  { :sort => [{ @field.indexed_name.to_sym => direction_for_solr }] }
end