Class: MmEsSearch::Api::Query::AbstractQuery

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::EmbeddedDocument
Defined in:
lib/mm_es_search/api/query/abstract_query.rb

Instance Method Summary collapse

Instance Method Details

#es_abs_fieldObject



14
15
16
17
18
19
20
21
22
# File 'lib/mm_es_search/api/query/abstract_query.rb', line 14

def es_abs_field
  if path?
    mod_path, indx = path_and_index
    return [mod_path, field].join('.')
  else
    return field
  end
  #TODO make sure we don't need to prefix path anymore - looks like we do if same name used at diff nesting levels, so always include to be safe
end

#mongo_abs_fieldObject



24
25
26
27
# File 'lib/mm_es_search/api/query/abstract_query.rb', line 24

def mongo_abs_field
  mod_path, array_index = path_and_index
  return array_index.nil? ? field : [path, field].join('.')
end

#path_and_indexObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mm_es_search/api/query/abstract_query.rb', line 29

def path_and_index
  
  case path
  when /(?<=\.)[0-9]+$/
    mod_path = path.gsub(/\.[0-9]+/,'')
    array_index = path.split('.').last.to_i
  else
    mod_path = path
    array_index = nil
  end
  
  return mod_path, array_index
  
end

#to_filterObject



10
11
12
# File 'lib/mm_es_search/api/query/abstract_query.rb', line 10

def to_filter
  QueryFilter.new(query: self)
end