Class: Stretchy::Clauses::MatchClause
- 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
-
#initialize(base, opts_or_str = {}, options = {}) ⇒ MatchClause
constructor
A new instance of MatchClause.
- #not(opts_or_str = {}, options = {}) ⇒ Object
- #should(opts_or_str = {}, options = {}) ⇒ Object
- #should? ⇒ Boolean
- #to_boost(weight = nil) ⇒ Object
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 = {}, = {}) super(base) if opts_or_str.is_a?(Hash) @inverse = opts_or_str.delete(:inverse) || .delete(:inverse) @should = opts_or_str.delete(:should) || .delete(:should) add_params(.merge(opts_or_str)) else @inverse = .delete(:inverse) @should = .delete(:should) add_params(.merge('_all' => opts_or_str)) end end |
Class Method Details
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 = {}, = {}) self.class.new(self, opts_or_str, .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 = {}, = {}) self.class.new(self, opts_or_str, .merge(should: true)) end |
#should? ⇒ 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 |