module Elastics::Scope::FilterMethods
Public Instance Methods
filters(*value)
click to toggle source
accepts one or an array or a list of filter structures
# File lib/elastics/scope/filter_methods.rb, line 22 def filters(*value) deep_merge boolean_wrapper( :filters => array_value(value) ) end
missing(*fields)
click to toggle source
# File lib/elastics/scope/filter_methods.rb, line 26 def missing(*fields) missing_list = [] for field in fields missing_list.push(:missing => field) end deep_merge :_missing_list => missing_list end
range(value)
click to toggle source
accepts one hash of ranges documented at www.elasticsearch.org/guide/reference/query-dsl/range-filter/
# File lib/elastics/scope/filter_methods.rb, line 45 def range(value) deep_merge boolean_wrapper(:range => value) end
term(term_or_terms_hash)
click to toggle source
accepts a single key hash or a multiple keys hash, that will be translated in a array of single key hashes
# File lib/elastics/scope/filter_methods.rb, line 35 def term(term_or_terms_hash) term_list = [] term_or_terms_hash.each do |term, value| term_list.push(:term => {term => value}) end deep_merge boolean_wrapper(:term_list => term_list) end
terms(value)
click to toggle source
accepts also :any_term => nil for missing values
# File lib/elastics/scope/filter_methods.rb, line 8 def terms(value) terms, missing_list = {}, [] value.each { |f, v| v.nil? ? missing_list.push({ :missing => f }) : (terms[f] = v) } terms, term = terms.partition{|k,v| v.is_a?(Array)} term_list = [] term.each do |term, value| term_list.push(:term => {term => value}) end deep_merge boolean_wrapper( :terms_list => Hash[terms], :term_list => term_list, :_missing_list => missing_list ) end
Private Instance Methods
boolean_wrapper(value)
click to toggle source
# File lib/elastics/scope/filter_methods.rb, line 66 def boolean_wrapper(value) if context_scope? if has_key?(:_boolean_wrapper) && self[:_boolean_wrapper] != :_and current_wrapper = {self[:_boolean_wrapper] => delete(self[:_boolean_wrapper])} self.and{ current_wrapper }.and{ value } else self.and{value} end else value end end
context_scope?()
click to toggle source
# File lib/elastics/scope/filter_methods.rb, line 62 def context_scope? has_key?(:context) end