Sha256: 8190f7d0a85d60b82ac7ce888d83cb13b3b814f64462da52d64575f1aafa6f35

Contents?: true

Size: 1.04 KB

Versions: 49

Compression:

Stored size: 1.04 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?
        !!@tag
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 11 rubygems

Version Path
gojee-sunspot-2.0.5 lib/sunspot/query/filter.rb
sunspot-2.0.0.pre.120925 lib/sunspot/query/filter.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/query/filter.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/query/filter.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/query/filter.rb
gojee-sunspot-2.0.4 lib/sunspot/query/filter.rb
gojee-sunspot-2.0.2 lib/sunspot/query/filter.rb
sunspot-2.0.0.pre.120720 lib/sunspot/query/filter.rb
sunspot-1.3.3 lib/sunspot/query/filter.rb
sunspot-1.3.2 lib/sunspot/query/filter.rb
sunspot-2.0.0.pre.120417 lib/sunspot/query/filter.rb
sunspot-2.0.0.pre.120415 lib/sunspot/query/filter.rb
sunspot-1.3.1 lib/sunspot/query/filter.rb
erichummel-sunspot-2.0.0.pre.111215d lib/sunspot/query/filter.rb
erichummel-sunspot-2.0.0.pre.111215c lib/sunspot/query/filter.rb
erichummel-sunspot-2.0.0.pre.111215b lib/sunspot/query/filter.rb
erichummel-sunspot-2.0.0.pre.111215a lib/sunspot/query/filter.rb
erichummel-sunspot-2.0.0.pre.111215 lib/sunspot/query/filter.rb
sunspot-2.0.0.pre.111215 lib/sunspot/query/filter.rb
cb_sunspot-2.0.0.pre.5 lib/sunspot/query/filter.rb