Class: Stretchy::Builders::MatchBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/stretchy/builders/match_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMatchBuilder

Returns a new instance of MatchBuilder.



7
8
9
10
11
12
# File 'lib/stretchy/builders/match_builder.rb', line 7

def initialize
  @must       = QueryBuilder.new
  @must_not   = QueryBuilder.new
  @should     = QueryBuilder.new
  @should_not = QueryBuilder.new
end

Instance Attribute Details

#mustObject

Returns the value of attribute must.



5
6
7
# File 'lib/stretchy/builders/match_builder.rb', line 5

def must
  @must
end

#must_notObject

Returns the value of attribute must_not.



5
6
7
# File 'lib/stretchy/builders/match_builder.rb', line 5

def must_not
  @must_not
end

#shouldObject

Returns the value of attribute should.



5
6
7
# File 'lib/stretchy/builders/match_builder.rb', line 5

def should
  @should
end

#should_notObject

Returns the value of attribute should_not.



5
6
7
# File 'lib/stretchy/builders/match_builder.rb', line 5

def should_not
  @should_not
end

Instance Method Details

#add_matches(field, matches, options = {}) ⇒ Object



18
19
20
# File 'lib/stretchy/builders/match_builder.rb', line 18

def add_matches(field, matches, options = {})
  builder_from_options(options).add_matches(field, matches, options)
end

#any?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/stretchy/builders/match_builder.rb', line 14

def any?
  must.any? || must_not.any? || should.any? || should_not.any?
end

#to_queryObject



22
23
24
25
26
27
28
29
30
# File 'lib/stretchy/builders/match_builder.rb', line 22

def to_query
  return Stretchy::Queries::MatchAllQuery.new unless any?

  if use_bool?
    bool_query
  else
    must.to_query.first
  end
end