Class: Elasticated::QueryConditions

Inherits:
Object
  • Object
show all
Includes:
ConditionsBuilder, Mixins::Clonable, Mixins::Inspectionable
Defined in:
lib/elasticated/query_conditions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConditionsBuilder

#boolean, #custom, #exists, #greater_equal, #greater_than, #less_equal, #less_than, #missing, #nested, #now, #range, #script, #term, #terms, #wildcard, #with

Methods included from Mixins::BlockEvaluation

#evaluate

Methods included from Mixins::Inspectionable

#inspect, #text_for_inspect

Methods included from Mixins::Clonable

#==, #clone

Constructor Details

#initializeQueryConditions

Returns a new instance of QueryConditions.



9
10
11
12
13
# File 'lib/elasticated/query_conditions.rb', line 9

def initialize
  self._must = BooleanClause.new
  self._must_not = BooleanClause.new
  self._should = BooleanClause.new
end

Instance Attribute Details

#_cacheObject

Returns the value of attribute _cache.



7
8
9
# File 'lib/elasticated/query_conditions.rb', line 7

def _cache
  @_cache
end

#_minimum_should_matchObject

Returns the value of attribute _minimum_should_match.



7
8
9
# File 'lib/elasticated/query_conditions.rb', line 7

def _minimum_should_match
  @_minimum_should_match
end

#_mustObject

Returns the value of attribute _must.



7
8
9
# File 'lib/elasticated/query_conditions.rb', line 7

def _must
  @_must
end

#_must_notObject

Returns the value of attribute _must_not.



7
8
9
# File 'lib/elasticated/query_conditions.rb', line 7

def _must_not
  @_must_not
end

#_shouldObject

Returns the value of attribute _should.



7
8
9
# File 'lib/elasticated/query_conditions.rb', line 7

def _should
  @_should
end

Instance Method Details

#add(condition) ⇒ Object

conditions



23
24
25
# File 'lib/elasticated/query_conditions.rb', line 23

def add(condition)
  _must.add condition
end

#buildObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/elasticated/query_conditions.rb', line 67

def build
  if empty?
    { match_all: {} }
  elsif _must_not.empty? && _should.empty? && _must.count == 1
    _must.build_first
  elsif _must_not.empty? && _must.empty? && _should.count == 1
    _should.build_first
  else
    bool = {}
    bool.merge! must: _must.build unless _must.empty?
    bool.merge! must_not: _must_not.build unless _must_not.empty?
    if !_should.empty?
      bool.merge! should: _should.build
      bool.merge! minimum_should_match: _minimum_should_match if _minimum_should_match
    end
    bool.merge! _cache: _cache if _cache
    { bool: bool }
  end
end

#cache(value = true) ⇒ Object

cache



57
58
59
# File 'lib/elasticated/query_conditions.rb', line 57

def cache(value=true)
  self._cache = value
end

#empty?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/elasticated/query_conditions.rb', line 87

def empty?
  _must.empty? && _must_not.empty? && _should.empty?
end

#fill_delimiter(field_delimiter) ⇒ Object

delimiters



17
18
19
# File 'lib/elasticated/query_conditions.rb', line 17

def fill_delimiter(field_delimiter)
  _must.fill_delimiter field_delimiter
end

#minimum_should_match(value) ⇒ Object

other methods



63
64
65
# File 'lib/elasticated/query_conditions.rb', line 63

def minimum_should_match(value)
  self._minimum_should_match = value
end

#must(&block) ⇒ Object



29
30
31
# File 'lib/elasticated/query_conditions.rb', line 29

def must(&block)
  _must.evaluate block
end

#must_not(&block) ⇒ Object



33
34
35
# File 'lib/elasticated/query_conditions.rb', line 33

def must_not(&block)
  _must_not.evaluate block
end

#not_between(*args) ⇒ Object



51
52
53
# File 'lib/elasticated/query_conditions.rb', line 51

def not_between(*args)
  _must_not.between *args
end

#not_equal(*args) ⇒ Object

‘must_not’ conditions



43
44
45
# File 'lib/elasticated/query_conditions.rb', line 43

def not_equal(*args)
  _must_not.equal *args
end

#should(&block) ⇒ Object



37
38
39
# File 'lib/elasticated/query_conditions.rb', line 37

def should(&block)
  _should.evaluate block
end

#without(*args) ⇒ Object



47
48
49
# File 'lib/elasticated/query_conditions.rb', line 47

def without(*args)
  _must_not.with *args
end