Module: Elos::QueryBuilder::Filters
Instance Method Summary collapse
- #and_filter(*filters) ⇒ Object
- #exists_filter(key) ⇒ Object
- #missing_filter(key) ⇒ Object
- #or_filter(*filters) ⇒ Object
- #range_filter(key, min: nil, max: nil) ⇒ Object
- #term_filter(key, params_sym = nil, value: nil) ⇒ Object
- #terms_filter(key, params_sym = nil, values: nil) ⇒ Object
Instance Method Details
#and_filter(*filters) ⇒ Object
10 11 12 13 14 |
# File 'lib/elos/query_builder/filters.rb', line 10 def and_filter(*filters) filters = filters.first if filters.first.is_a?(Array) filters.compact! { and: filters } unless filters.empty? end |
#exists_filter(key) ⇒ Object
26 27 28 |
# File 'lib/elos/query_builder/filters.rb', line 26 def exists_filter(key) { exists: { field: key } } end |
#missing_filter(key) ⇒ Object
30 31 32 |
# File 'lib/elos/query_builder/filters.rb', line 30 def missing_filter(key) { missing: { field: key } } end |
#or_filter(*filters) ⇒ Object
4 5 6 7 8 |
# File 'lib/elos/query_builder/filters.rb', line 4 def or_filter(*filters) filters = filters.first if filters.first.is_a?(Array) filters.compact! { or: filters } unless filters.empty? end |
#range_filter(key, min: nil, max: nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/elos/query_builder/filters.rb', line 34 def range_filter(key, min: nil, max: nil) return unless min || max r = { range: { key => {} } } r[:range][key][:gte] = min if min r[:range][key][:lte] = max if max r end |
#term_filter(key, params_sym = nil, value: nil) ⇒ Object
16 17 18 19 |
# File 'lib/elos/query_builder/filters.rb', line 16 def term_filter(key, params_sym = nil, value: nil) v = value.nil? ? params[params_sym || key] : value { term: { key => v } } unless v.nil? end |
#terms_filter(key, params_sym = nil, values: nil) ⇒ Object
21 22 23 24 |
# File 'lib/elos/query_builder/filters.rb', line 21 def terms_filter(key, params_sym = nil, values: nil) v = value.nil? ? params[params_sym || key.to_s.pluralize.to_sym] : value { terms: { key => v } } unless v.empty? end |