Class: MmEsSearch::Api::Query::RangeQuery
Instance Method Summary
collapse
#es_abs_field, #mongo_abs_field, #path_and_index, #to_filter
Instance Method Details
#to_es_query ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/mm_es_search/api/query/range_query.rb', line 38
def to_es_query
raise "must have either :from or :to" if from.nil? and to.nil?
range_params = {}
range_params.merge!({:from => from}) unless from.nil?
range_params.merge!({:to => to}) unless to.nil?
range_params.merge!({:include_lower => include_lower}) unless (from.nil? or include_lower == true)
range_params.merge!({:include_upper => include_upper}) unless (to.nil? or include_upper == true)
range_params.merge!({:boost => boost}) unless boost.nil?
return {:range => {es_abs_field => range_params}}
end
|
#to_mongo_query(options = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/mm_es_search/api/query/range_query.rb', line 16
def to_mongo_query(options = {})
range_params = {}
if from
cmd = include_lower ? '$gte' : '$gt'
range_params.merge!({cmd => from})
end
if to
cmd = include_upper ? '$lte' : '$lt'
range_params.merge!({cmd => to})
end
if options[:negated]
return {mongo_abs_field => {"$not" => range_params}}
else
return {mongo_abs_field => range_params}
end
end
|