Class: Elasticquery::Base

Inherits:
Object
  • Object
show all
Includes:
Builder
Defined in:
lib/elasticquery/base.rb

Direct Known Subclasses

BaseChain, Filters::Not

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Builder

#exists, #filters, #missing, #multi_match, #not, #queries, #range, #search, #term, #terms, #where, #with, #without

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



23
24
25
26
# File 'lib/elasticquery/base.rb', line 23

def initialize(params = {})
  @params = params
  @query = Query.new
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/elasticquery/base.rb', line 11

def params
  @params
end

#queryObject (readonly)

Returns the value of attribute query.



11
12
13
# File 'lib/elasticquery/base.rb', line 11

def query
  @query
end

Class Method Details

.build(params = {}) ⇒ Object



34
35
36
# File 'lib/elasticquery/base.rb', line 34

def self.build(params = {})
  new(params).build
end

.filtered(&block) ⇒ Object



15
16
17
# File 'lib/elasticquery/base.rb', line 15

def self.filtered(&block)
  self.rules += [block]
end

Instance Method Details

#buildObject



28
29
30
31
32
# File 'lib/elasticquery/base.rb', line 28

def build
  @namespace = nil
  rules.each { |rule| instance_exec @params, &rule }
  query.to_hash
end

#filterable?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/elasticquery/base.rb', line 19

def filterable?
  rules.any?
end