Sha256: ba7a96eb5cb31fd09c5ab61d5757d34786e6e18b0a9fdd3e263e16000556abc8

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Sunspot
  module Query
    class AbstractFieldFacet
      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
        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

6 entries across 6 versions & 1 rubygems

Version Path
sunspot-1.0.5 lib/sunspot/query/abstract_field_facet.rb
sunspot-1.0.4 lib/sunspot/query/abstract_field_facet.rb
sunspot-1.0.3 lib/sunspot/query/abstract_field_facet.rb
sunspot-1.0.2 lib/sunspot/query/abstract_field_facet.rb
sunspot-1.0.1 lib/sunspot/query/abstract_field_facet.rb
sunspot-1.0.0 lib/sunspot/query/abstract_field_facet.rb