Class: Sunspot::Query::Sort::RandomSort

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

Overview

A RandomSort uses Solr’s random field functionality to sort results (usually) randomly.

Instance Method Summary collapse

Constructor Details

#initialize(options = {:seed => rand(1<<16)}, direction = nil) ⇒ RandomSort

Returns a new instance of RandomSort.



79
80
81
# File 'lib/sunspot/query/sort.rb', line 79

def initialize(options={:seed => rand(1<<16)}, direction=nil)
  @seed, @direction = options[:seed], (direction || :asc).to_sym
end

Instance Method Details

#to_paramObject



83
84
85
# File 'lib/sunspot/query/sort.rb', line 83

def to_param
  "random_#{@seed} #{direction_for_solr}"
end