Class: Stretchy::Clauses::MatchClause

Inherits:
Base
  • Object
show all
Defined in:
lib/stretchy/clauses/match_clause.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_LIMIT, Base::DEFAULT_OFFSET

Instance Attribute Summary

Attributes inherited from Base

#aggregate_builder, #boost_builder, #index_name, #inverse, #match_builder, #type, #where_builder

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#boost, #get_limit, #get_offset, #inverse?, #limit, #match, #offset, #query_results, #to_search, #where

Constructor Details

#initialize(base, opts_or_str = {}, options = {}) ⇒ MatchClause

Returns a new instance of MatchClause.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stretchy/clauses/match_clause.rb', line 11

def initialize(base, opts_or_str = {}, options = {})
  super(base)
  if opts_or_str.is_a?(Hash)
    @inverse     = opts_or_str.delete(:inverse) || options.delete(:inverse)
    @should      = opts_or_str.delete(:should)  || options.delete(:should)
    add_params(options.merge(opts_or_str))
  else
    @inverse     = options.delete(:inverse)
    @should      = options.delete(:should)
    add_params(options.merge('_all' => opts_or_str))
  end
end

Class Method Details

.tmp(options = {}) ⇒ Object



7
8
9
# File 'lib/stretchy/clauses/match_clause.rb', line 7

def self.tmp(options = {})
  self.new(Base.new, options)
end

Instance Method Details

#not(opts_or_str = {}, options = {}) ⇒ Object



24
25
26
# File 'lib/stretchy/clauses/match_clause.rb', line 24

def not(opts_or_str = {}, options = {})
  self.class.new(self, opts_or_str, options.merge(inverse: true, should: should?))
end

#should(opts_or_str = {}, options = {}) ⇒ Object



28
29
30
# File 'lib/stretchy/clauses/match_clause.rb', line 28

def should(opts_or_str = {}, options = {})
  self.class.new(self, opts_or_str, options.merge(should: true))
end

#should?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/stretchy/clauses/match_clause.rb', line 42

def should?
  !!@should
end

#to_boost(weight = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/stretchy/clauses/match_clause.rb', line 32

def to_boost(weight = nil)
  weight ||= Stretchy::Boosts::FilterBoost::DEFAULT_WEIGHT
  Stretchy::Boosts::FilterBoost.new(
    filter: Stretchy::Filters::QueryFilter.new(
      @match_builder.build
    ),
    weight: weight
  )
end