Class: Sunspot::Search::RangeFacet
- Inherits:
-
Object
- Object
- Sunspot::Search::RangeFacet
- Defined in:
- lib/sunspot/search/range_facet.rb
Instance Method Summary collapse
- #field_name ⇒ Object
-
#initialize(field, search, options) ⇒ RangeFacet
constructor
A new instance of RangeFacet.
- #rows ⇒ Object
Constructor Details
#initialize(field, search, options) ⇒ RangeFacet
Returns a new instance of RangeFacet.
4 5 6 |
# File 'lib/sunspot/search/range_facet.rb', line 4 def initialize(field, search, ) @field, @search, @options = field, search, end |
Instance Method Details
#field_name ⇒ Object
8 9 10 |
# File 'lib/sunspot/search/range_facet.rb', line 8 def field_name @field.name end |
#rows ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |