Class: Elasticated::QueryConditions
- Inherits:
-
Object
- Object
- Elasticated::QueryConditions
- Includes:
- ConditionsBuilder, Mixins::Clonable, Mixins::Inspectionable
- 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
-
#add(condition) ⇒ Object
conditions.
- #build ⇒ Object
-
#cache(value = true) ⇒ Object
cache.
- #empty? ⇒ Boolean
-
#fill_delimiter(field_delimiter) ⇒ Object
delimiters.
-
#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
#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
Methods included from Mixins::Inspectionable
Methods included from Mixins::Clonable
Constructor Details
#initialize ⇒ QueryConditions
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
#_cache ⇒ Object
Returns the value of attribute _cache.
7 8 9 |
# File 'lib/elasticated/query_conditions.rb', line 7 def _cache @_cache end |
#_minimum_should_match ⇒ Object
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 |
#_must ⇒ Object
Returns the value of attribute _must.
7 8 9 |
# File 'lib/elasticated/query_conditions.rb', line 7 def _must @_must end |
#_must_not ⇒ Object
Returns the value of attribute _must_not.
7 8 9 |
# File 'lib/elasticated/query_conditions.rb', line 7 def _must_not @_must_not end |
#_should ⇒ Object
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 |
#build ⇒ Object
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
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 |