Class: Lycra::Search::Query

Inherits:
Array
  • Object
show all
Defined in:
lib/lycra/search/query.rb

Instance Method Summary collapse

Instance Method Details

#filter(fltr = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/lycra/search/query.rb', line 21

def filter(fltr=nil)
  if fltr.present?
    filters << fltr
  end

  self
end

#filtersObject



17
18
19
# File 'lib/lycra/search/query.rb', line 17

def filters
  @filters ||= Lycra::Search::Filters.new
end

#refilter(fltr) ⇒ Object



29
30
31
32
# File 'lib/lycra/search/query.rb', line 29

def refilter(fltr)
  @filters = Lycra::Search::Filters.new
  filter fltr
end

#to_queryObject Also known as: to_q



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/lycra/search/query.rb', line 4

def to_query
  return {} if empty? && filters.empty?

  query_matcher = {}
  query_matcher.merge!(must_matchers) unless must_matchers.empty?
  query_matcher.merge!(should_matchers) unless should_matchers.empty?
  query_filters = {filter: filters.to_query}
  {
    bool: query_matcher.merge(query_filters)
  }
end