Sha256: 645af9db01ba3bdb04b6c028567f6949993b6abdc99f352ab6905d3d39bca2ea

Contents?: true

Size: 994 Bytes

Versions: 27

Compression:

Stored size: 994 Bytes

Contents

module Sunspot
  module Search
    class RangeFacet
      def initialize(field, search, options)
        @field, @search, @options = field, search, options
      end

      def field_name
        @field.name
      end

      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
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/search/range_facet.rb
sunspot-2.7.0 lib/sunspot/search/range_facet.rb
sunspot-2.6.0 lib/sunspot/search/range_facet.rb
sunspot-2.5.0 lib/sunspot/search/range_facet.rb
sunspot-2.4.0 lib/sunspot/search/range_facet.rb
sunspot-2.3.0 lib/sunspot/search/range_facet.rb
sunspot-2.2.8 lib/sunspot/search/range_facet.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/search/range_facet.rb
sunspot-2.2.7 lib/sunspot/search/range_facet.rb
sunspot-2.2.6 lib/sunspot/search/range_facet.rb
sunspot-2.2.5 lib/sunspot/search/range_facet.rb
sunspot-2.2.4 lib/sunspot/search/range_facet.rb
sunspot-2.2.3 lib/sunspot/search/range_facet.rb
sunspot-2.2.2 lib/sunspot/search/range_facet.rb
sunspot-2.2.1 lib/sunspot/search/range_facet.rb
sunspot-2.2.0 lib/sunspot/search/range_facet.rb
sunspot-2.1.1 lib/sunspot/search/range_facet.rb
sunspot-2.1.0 lib/sunspot/search/range_facet.rb
sunspot-2.0.0 lib/sunspot/search/range_facet.rb
sunspot-2.0.0.pre.130115 lib/sunspot/search/range_facet.rb