Sha256: fa7b3a4d60e080780f667a83ce10632ddbad0d87ee688c9a421dd4faad6ecbb4

Contents?: true

Size: 1.36 KB

Versions: 20

Compression:

Stored size: 1.36 KB

Contents

module Sunspot
  module Query

    class RangeFacet < AbstractFieldFacet
      def initialize(field, options)
        if exclude_filters = options[:exclude]
          @exclude_tag = Util.Array(exclude_filters).map do |filter|
            filter.tag
          end.join(',')
        end
        super
      end

      def to_params
        params = super
        params[:"facet.range"] = [field_name_with_local_params]
        params[qualified_param('range.start')] = @field.to_indexed(@options[:range].first)
        params[qualified_param('range.end')] = @field.to_indexed(@options[:range].last)
        params[qualified_param('range.gap')] = "#{@options[:range_interval] || 10}"
        params[qualified_param('range.include')] = @options[:include].to_s if @options[:include]
        params
      end

      private

      def local_params
        @local_params ||=
          begin
            local_params = {}
            local_params[:ex] = @exclude_tag if @exclude_tag
            local_params[:key] = @options[:name] if @options[:name]
            local_params
          end
      end

      def field_name_with_local_params
        if local_params.empty?
          @field.indexed_name
        else
          pairs = local_params.map do |key, value|
            "#{key}=#{value}"
          end
          "{!#{pairs.join(' ')}}#{@field.indexed_name}"
        end
      end
    end

  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

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