Sha256: c51cd34c8d88f5c9451b89393dee9afb4cc4c9be7b8ee35829163927f1b99ca8

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

module Sunspot
  module Query
    module Filter

      # 
      # Express this filter as an :fq parameter; i.e., the boolean phrase,
      # maybe prefixed by local params.
      #
      def to_filter_query
        if tagged? then "{!tag=#{tag}}#{to_boolean_phrase}"
        else to_boolean_phrase
        end
      end

      #
      # Generate and return a tag that can be attached to this restriction,
      # for use with multiselect faceting. This needs to be unique, but doesn't
      # really need to be human-readable, so just generate a string based on the
      # hash of the boolean phrase.
      #
      def tag
        @tag ||= to_boolean_phrase.hash.abs.to_s(36)
      end
      
      private

      # 
      # True if a tag has been generated for this filter (e.g., if it's been
      # excluded from a given facet). If a tag has not been generated at the
      # time that the filter query param is requested, then it is not necessary
      # to include a tag in the local params.
      #
      def tagged?
        defined?(@tag) && !!@tag
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

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