class Sunspot::Search::RangeFacet

Public Class Methods

new(field, search, options) click to toggle source
# File lib/sunspot/search/range_facet.rb, line 4
def initialize(field, search, options)
  @field, @search, @options = field, search, options
end

Public Instance Methods

field_name() click to toggle source
# File lib/sunspot/search/range_facet.rb, line 8
def field_name
  @field.name
end
rows() click to toggle source
# File lib/sunspot/search/range_facet.rb, line 12
def rows
  @rows ||=
    begin
      data = @search.facet_response['facet_ranges'][@field.indexed_name]
      gap = (@options[:range_interval] || 10).to_i
      rows = []
      
      if data['counts']
        Hash[*data['counts']].each_pair do |start_str, count|
          start = start_str.to_f
          finish = start + gap
          rows << FacetRow.new(start..finish, count, self)
        end
      end

      if @options[:sort] == :count
        rows.sort! { |lrow, rrow| rrow.count <=> lrow.count }
      else
        rows.sort! { |lrow, rrow| lrow.value.first <=> rrow.value.first }
      end
      rows
    end
end