Sha256: 79a8caea29b242eae867c802f4570e2ace72433fcf9f990db5cfb5d16a8f36be

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module Sunspot
  module Query
    class AbstractFieldFacet
      include RSolr::Char

      def initialize(field, options)
        @field, @options = field, options
      end

      def to_params
        params = {
          :facet => 'true',
        }
        case @options[:sort]
        when :count
          params[qualified_param('sort')] = 'true'
        when :index
          params[qualified_param('sort')] = 'false'
        when nil
        else
          raise(
            ArgumentError,
            "#{@options[:sort].inspect} is not an allowed value for :sort. Allowed options are :count and :index"
          )
        end
        if @options[:limit]
          params[qualified_param('limit')] = @options[:limit].to_i
        end
        if @options[:offset]
          params[qualified_param('offset')] = @options[:offset].to_i
        end
        if @options[:prefix]
          params[qualified_param('prefix')] = escape(@options[:prefix].to_s)
        end
        params[qualified_param('mincount')] = 
          case
          when @options[:minimum_count] then @options[:minimum_count].to_i
          when @options[:zeros] then 0
          else 1
          end
        params
      end

      private

      def qualified_param(param)
        :"f.#{key}.facet.#{param}"
      end
      
      def key
        @key ||= @options[:name] || @field.indexed_name
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sunspot-2.0.0.pre.120720 lib/sunspot/query/abstract_field_facet.rb
sunspot-2.0.0.pre.120417 lib/sunspot/query/abstract_field_facet.rb
sunspot-2.0.0.pre.120415 lib/sunspot/query/abstract_field_facet.rb