module Relix::Index::Ordering

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/relix/index.rb, line 98
def initialize(*args)
  super
  @order = @options[:order]
end

Public Instance Methods

range_from_options(r, options, value=nil) click to toggle source
# File lib/relix/index.rb, line 130
def range_from_options(r, options, value=nil)
  start = (options[:offset] || 0)
  if f = options[:from]
    start = (position(r, f, value) + 1)
  end
  stop = (options[:limit] ? (start + options[:limit] - 1) : -1)
  [start, stop]
end
score(object, value) click to toggle source
# File lib/relix/index.rb, line 103
def score(object, value)
  if @order
    value = object.send(@order)
  end

  score_for_value(value)
end
score_for_value(value) click to toggle source
# File lib/relix/index.rb, line 111
def score_for_value(value)
  case value
  when Numeric
    value
  when Time
    value.to_f
  else
    if value.respond_to?(:to_i)
      value.to_i
    elsif value.respond_to?(:to_time)
      value.to_time.to_f
    elsif @order
      raise UnorderableValueError.new("Unable to convert #{value} in to a number for ordering.")
    else
      0
    end
  end
end