Class: MmEsSearch::Api::Query::TermsQuery
Instance Method Summary
collapse
#es_abs_field, #mongo_abs_field, #path_and_index, #to_filter
Instance Method Details
#get_object_value(obj, path, field) ⇒ Object
17
18
19
20
|
# File 'lib/mm_es_search/api/query/terms_query.rb', line 17
def get_object_value(obj,path,field)
method_arg_array = [path,field].join('.').split('.').map {|m| m =~ /^\d+$/ ? [:slice, m.to_i] : [m] }
method_arg_array.inject(obj) {|obj, method_and_args| obj.send(*method_and_args)}
end
|
#run_analyzer(obj, path, field) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/mm_es_search/api/query/terms_query.rb', line 22
def run_analyzer(obj,path,field)
val = get_object_value(obj,path,field)
case val
when String
val.split
when Array
val.flatten.join(' ').split
end
end
|
#to_es_query ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/mm_es_search/api/query/terms_query.rb', line 46
def to_es_query
terms_params = {es_abs_field => terms}
terms_params.merge!(:boost => boost) if boost?
terms_params.merge!(:minimum_match => minimum_match) if minimum_match?
terms_params.merge!(:execution => execution) if execution?
return {:terms => terms_params}
end
|
#to_mongo_query(options = {}) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/mm_es_search/api/query/terms_query.rb', line 37
def to_mongo_query(options = {})
if options[:negated]
{mongo_abs_field => {'$nin' => terms}}
else
{mongo_abs_field => {'$in' => terms}}
end
end
|
#to_object_query ⇒ Object
33
34
35
|
# File 'lib/mm_es_search/api/query/terms_query.rb', line 33
def to_object_query
return ->(obj){ (run_analyzer(obj,path,field) & terms).any? }
end
|