module ElasticQueue::Filters
Public Instance Methods
options_to_filters(options)
click to toggle source
# File lib/elastic_queue/filters.rb, line 8 def options_to_filters(options) options.map { |k, v| option_to_filter(k, v) }.flatten end
Private Instance Methods
comparison_filter(term, value)
click to toggle source
take something like follow_up: { before: ‘hii’, after: ‘low’ }
# File lib/elastic_queue/filters.rb, line 47 def comparison_filter(term, value) value.map do |k, v| comparator = k.to_sym.in?([:after, :greater_than, :gt]) ? :gt : :lt range_filter(term, v, comparator) end end
join_options(operator, options)
click to toggle source
# File lib/elastic_queue/filters.rb, line 31 def join_options(operator, options) conditions = options.map { |o| options_to_filters(o) }.flatten { operator => conditions } end
null_filter(term, value)
click to toggle source
# File lib/elastic_queue/filters.rb, line 59 def null_filter(term, value) { missing: { field: term, existence: true, null_value: true } } end
option_to_filter(key, value)
click to toggle source
# File lib/elastic_queue/filters.rb, line 14 def option_to_filter(key, value) # return and_options(value) if key == :and if [:or, :and].include?(key) join_options(key, value) elsif value.is_a? Array or_filter(key, value) elsif value.is_a? Hash comparison_filter(key, value) elsif value.nil? # e.g. name: nil null_filter(key, value) else # e.g. status: 'fresh' term_filter(key, value) end end
or_filter(term, values)
click to toggle source
# File lib/elastic_queue/filters.rb, line 36 def or_filter(term, values) # flatten here because ranges return arrays conditions = values.map { |v| option_to_filter(term, v) }.flatten { or: conditions } end
range_filter(term, value, comparator)
click to toggle source
like term filter but for comparison queries
# File lib/elastic_queue/filters.rb, line 55 def range_filter(term, value, comparator) { range: { term => { comparator => value } } } end
term_filter(term, value)
click to toggle source
# File lib/elastic_queue/filters.rb, line 42 def term_filter(term, value) { term: { term => value } } end