Class: Sunspot::Query::SortComposite

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

Constructor Details

#initializeSortComposite

:nodoc:



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

def initialize
  @sorts = []
end

Instance Method Details

#<<(sort) ⇒ Object

Add a sort to the composite



17
18
19
# File 'lib/sunspot/query/sort_composite.rb', line 17

def <<(sort)
  @sorts << sort
end

#to_paramsObject

Combine the sorts into a single param by joining them



24
25
26
27
28
29
30
# File 'lib/sunspot/query/sort_composite.rb', line 24

def to_params
  unless @sorts.empty?
    { :sort => @sorts.map { |sort| sort.to_param } * ', ' }
  else
    {}
  end
end