Class: Elasticated::QueryConditions
- Inherits:
-
Object
- Object
- Elasticated::QueryConditions
- Includes:
- Clonable, ConditionsBuilder
- Defined in:
- lib/elasticated/query_conditions.rb
Instance Attribute Summary collapse
-
#_cache ⇒ Object
Returns the value of attribute _cache.
-
#_minimum_should_match ⇒ Object
Returns the value of attribute _minimum_should_match.
-
#_must ⇒ Object
Returns the value of attribute _must.
-
#_must_not ⇒ Object
Returns the value of attribute _must_not.
-
#_should ⇒ Object
Returns the value of attribute _should.
Instance Method Summary collapse
- #accept_visitor(visitor) ⇒ Object
-
#add(condition) ⇒ Object
conditions.
- #build ⇒ Object
-
#cache(value = true) ⇒ Object
cache.
- #empty? ⇒ Boolean
-
#initialize ⇒ QueryConditions
constructor
A new instance of QueryConditions.
-
#minimum_should_match(value) ⇒ Object
other methods.
- #must(&block) ⇒ Object
- #must_not(&block) ⇒ Object
- #not_between(*args) ⇒ Object
-
#not_equal(*args) ⇒ Object
‘must_not’ conditions.
- #should(&block) ⇒ Object
- #without(*args) ⇒ Object
Methods included from ConditionsBuilder
#between, #boolean, #custom, #equal, #exists, #greater_equal, #greater_than, #less_equal, #less_than, #missing, #nested, #script, #wildcard, #with
Methods included from BlockEvaluation
Methods included from Clonable
Constructor Details
#initialize ⇒ QueryConditions
Returns a new instance of QueryConditions.
8 9 10 11 12 |
# File 'lib/elasticated/query_conditions.rb', line 8 def initialize self._must = BooleanClause.new self._must_not = BooleanClause.new self._should = BooleanClause.new end |
Instance Attribute Details
#_cache ⇒ Object
Returns the value of attribute _cache.
6 7 8 |
# File 'lib/elasticated/query_conditions.rb', line 6 def _cache @_cache end |
#_minimum_should_match ⇒ Object
Returns the value of attribute _minimum_should_match.
6 7 8 |
# File 'lib/elasticated/query_conditions.rb', line 6 def _minimum_should_match @_minimum_should_match end |
#_must ⇒ Object
Returns the value of attribute _must.
6 7 8 |
# File 'lib/elasticated/query_conditions.rb', line 6 def _must @_must end |
#_must_not ⇒ Object
Returns the value of attribute _must_not.
6 7 8 |
# File 'lib/elasticated/query_conditions.rb', line 6 def _must_not @_must_not end |
#_should ⇒ Object
Returns the value of attribute _should.
6 7 8 |
# File 'lib/elasticated/query_conditions.rb', line 6 def _should @_should end |
Instance Method Details
#accept_visitor(visitor) ⇒ Object
14 15 16 |
# File 'lib/elasticated/query_conditions.rb', line 14 def accept_visitor(visitor) visitor.visit_query_conditions(self) end |
#add(condition) ⇒ Object
conditions
20 21 22 |
# File 'lib/elasticated/query_conditions.rb', line 20 def add(condition) _must.add condition end |
#build ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/elasticated/query_conditions.rb', line 64 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
54 55 56 |
# File 'lib/elasticated/query_conditions.rb', line 54 def cache(value=true) self._cache = value end |
#empty? ⇒ Boolean
84 85 86 |
# File 'lib/elasticated/query_conditions.rb', line 84 def empty? _must.empty? && _must_not.empty? && _should.empty? end |
#minimum_should_match(value) ⇒ Object
other methods
60 61 62 |
# File 'lib/elasticated/query_conditions.rb', line 60 def minimum_should_match(value) self._minimum_should_match = value end |
#must(&block) ⇒ Object
26 27 28 |
# File 'lib/elasticated/query_conditions.rb', line 26 def must(&block) _must.evaluate block end |
#must_not(&block) ⇒ Object
30 31 32 |
# File 'lib/elasticated/query_conditions.rb', line 30 def must_not(&block) _must_not.evaluate block end |
#not_between(*args) ⇒ Object
48 49 50 |
# File 'lib/elasticated/query_conditions.rb', line 48 def not_between(*args) _must_not.between *args end |
#not_equal(*args) ⇒ Object
‘must_not’ conditions
40 41 42 |
# File 'lib/elasticated/query_conditions.rb', line 40 def not_equal(*args) _must_not.equal *args end |
#should(&block) ⇒ Object
34 35 36 |
# File 'lib/elasticated/query_conditions.rb', line 34 def should(&block) _should.evaluate block end |
#without(*args) ⇒ Object
44 45 46 |
# File 'lib/elasticated/query_conditions.rb', line 44 def without(*args) _must_not.with *args end |