Class: Sunspot::Query::Sort::FieldSort

Inherits:
Abstract
  • Object
show all
Defined in:
lib/sunspot/query/sort.rb

Overview

A FieldSort is the usual kind of sort, by the value of a particular field, ascending or descending

Direct Known Subclasses

GeodistSort

Instance Method Summary collapse

Constructor Details

#initialize(field, direction = nil) ⇒ FieldSort

Returns a new instance of FieldSort.



62
63
64
65
66
67
# File 'lib/sunspot/query/sort.rb', line 62

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



69
70
71
# File 'lib/sunspot/query/sort.rb', line 69

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