Class: Eson::Search::BaseQuery

Inherits:
Object
  • Object
show all
Includes:
Facets, Parametrized, QueryGroup
Defined in:
lib/eson/search/base_query.rb

Instance Attribute Summary

Attributes included from Parametrized

#args

Attributes included from Queries

#queries

Attributes included from Filters

#filters

Instance Method Summary collapse

Methods included from Parametrized

#param

Methods included from Facets

#facets, register

Methods included from QueryGroup

#to_hash

Methods included from Queries

#queries?, register

Methods included from Filters

#filters?, register

Constructor Details

#initialize(args = {}) ⇒ BaseQuery

Returns a new instance of BaseQuery.



8
9
10
11
# File 'lib/eson/search/base_query.rb', line 8

def initialize(args = {})
  self.args = args
  instance_exec(self, &Proc.new) if block_given?
end

Instance Method Details

#to_query_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/eson/search/base_query.rb', line 13

def to_query_hash
  if (!queries || queries.empty?)
    hash = {:query => {:match_all => {}}}
  else
    hash = {:query => queries.to_query_hash }
  end

  if filters && !filters.empty?
    if filters.length > 1
      hash[:filter] = {:and => filter.to_query_hash}
    else
      hash[:filter] = filter.to_query_hash
    end
  end

  if facets.length > 0
    hash[:facets] = facets.to_query_hash
  end

  hash
end