Class: MmEsSearch::Api::Query::PrefixQuery

Inherits:
AbstractQuery show all
Defined in:
lib/mm_es_search/api/query/prefix_query.rb

Direct Known Subclasses

PrefixFilter

Instance Method Summary collapse

Methods inherited from AbstractQuery

#es_abs_field, #mongo_abs_field, #path_and_index, #to_filter

Instance Method Details

#to_es_queryObject



22
23
24
25
26
27
28
# File 'lib/mm_es_search/api/query/prefix_query.rb', line 22

def to_es_query
  if boost
    {:prefix => {es_abs_field => {:value => value, :boost => boost}}} 
  else
    {:prefix => {es_abs_field => value}}
  end
end

#to_mongo_query(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/mm_es_search/api/query/prefix_query.rb', line 13

def to_mongo_query(options = {})
  prefix_regex = /^#{value}/
  if options[:negated]
    {mongo_abs_field => {'$ne' => prefix_regex}}
  else
    {mongo_abs_field => prefix_regex}
  end
end