Class: Stretchy::Builders::MatchBuilder
- Inherits:
-
Object
- Object
- Stretchy::Builders::MatchBuilder
- Defined in:
- lib/stretchy/builders/match_builder.rb
Instance Attribute Summary collapse
-
#antimatches ⇒ Object
Returns the value of attribute antimatches.
-
#antimatchops ⇒ Object
Returns the value of attribute antimatchops.
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#matchops ⇒ Object
Returns the value of attribute matchops.
-
#shouldmatches ⇒ Object
Returns the value of attribute shouldmatches.
-
#shouldmatchops ⇒ Object
Returns the value of attribute shouldmatchops.
-
#shouldnotmatches ⇒ Object
Returns the value of attribute shouldnotmatches.
-
#shouldnotmatchops ⇒ Object
Returns the value of attribute shouldnotmatchops.
Instance Method Summary collapse
- #any? ⇒ Boolean
- #bool_query ⇒ Object
- #build ⇒ Object
- #build_should ⇒ Object
-
#initialize ⇒ MatchBuilder
constructor
A new instance of MatchBuilder.
Constructor Details
#initialize ⇒ MatchBuilder
Returns a new instance of MatchBuilder.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/stretchy/builders/match_builder.rb', line 10 def initialize @matches = Hash.new { [] } @matchops = Hash.new { 'and' } @antimatches = Hash.new { [] } @antimatchops = Hash.new { 'and' } @shouldmatches = Hash.new { [] } @shouldmatchops = Hash.new { 'and' } @shouldnotmatches = Hash.new { [] } @shouldnotmatchops = Hash.new { 'and' } end |
Instance Attribute Details
#antimatches ⇒ Object
Returns the value of attribute antimatches.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def antimatches @antimatches end |
#antimatchops ⇒ Object
Returns the value of attribute antimatchops.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def antimatchops @antimatchops end |
#matches ⇒ Object
Returns the value of attribute matches.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def matches @matches end |
#matchops ⇒ Object
Returns the value of attribute matchops.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def matchops @matchops end |
#shouldmatches ⇒ Object
Returns the value of attribute shouldmatches.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def shouldmatches @shouldmatches end |
#shouldmatchops ⇒ Object
Returns the value of attribute shouldmatchops.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def shouldmatchops @shouldmatchops end |
#shouldnotmatches ⇒ Object
Returns the value of attribute shouldnotmatches.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def shouldnotmatches @shouldnotmatches end |
#shouldnotmatchops ⇒ Object
Returns the value of attribute shouldnotmatchops.
5 6 7 |
# File 'lib/stretchy/builders/match_builder.rb', line 5 def shouldnotmatchops @shouldnotmatchops end |
Instance Method Details
#any? ⇒ Boolean
24 25 26 |
# File 'lib/stretchy/builders/match_builder.rb', line 24 def any? @matches.any? || @antimatches.any? || @shouldmatches.any? || @shouldnotmatches.any? end |
#bool_query ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/stretchy/builders/match_builder.rb', line 40 def bool_query Stretchy::Queries::BoolQuery.new( must: to_queries(@matches, @matchops), must_not: to_queries(@antimatches, @antimatchops), should: build_should ) end |
#build ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stretchy/builders/match_builder.rb', line 28 def build return Stretchy::Queries::MatchAllQuery.new unless any? if @matches.count > 1 || @antimatches.any? || @shouldmatches.any? || @shouldnotmatches.any? bool_query else to_queries(@matches, @matchops).first end end |
#build_should ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/stretchy/builders/match_builder.rb', line 48 def build_should if @shouldnotmatches.any? Stretchy::Queries::BoolQuery.new( must: to_queries(@shouldmatches, @shouldmatchops), must_not: to_queries(@shouldnotmatches, @shouldnotmatchops) ) else to_queries(@shouldmatches, @shouldmatchops) end end |