Module: Sunspot::Query::Filter

Included in:
Connective::Abstract, Restriction::Base
Defined in:
lib/sunspot/query/filter.rb

Instance Method Summary collapse

Instance Method Details

#tagObject

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.



21
22
23
# File 'lib/sunspot/query/filter.rb', line 21

def tag
  @tag ||= to_boolean_phrase.hash.abs.to_s(36)
end

#to_filter_queryObject

Express this filter as an :fq parameter; i.e., the boolean phrase, maybe prefixed by local params.



9
10
11
12
13
# File 'lib/sunspot/query/filter.rb', line 9

def to_filter_query
  if tagged? then "{!tag=#{tag}}#{to_boolean_phrase}"
  else to_boolean_phrase
  end
end