Class: Stretchy::Clauses::MatchClause
- Defined in:
- lib/stretchy/clauses/match_clause.rb
Overview
A Match clause inherits the same state as any clause. There aren't any more specific methods to chain, as this clause only handles basic full-text searches.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.tmp(options = {}) ⇒ MatchClause
Creates a temporary MatchClause outside the main query scope by using a new Base.
Instance Method Summary collapse
-
#initialize(base, opts_or_str = {}, options = {}) ⇒ MatchClause
constructor
Creates a new state with a match query applied.
-
#not(opts_or_str = {}) ⇒ MatchClause
Switches to inverted context.
-
#should(opts_or_str = {}) ⇒ MatchClause
Switches to
should
context. -
#should? ⇒ true, false
Accessor for
@should
. -
#to_boost(weight = nil) ⇒ Stretchy::Boosts::FilterBoost
Converts this match context to a set of boosts to use in a Queries::FunctionScoreQuery.
Methods inherited from Base
#aggregations, #boost, #explain, #fields, #get_aggregations, #get_explain, #get_fields, #get_limit, #get_offset, #get_page, #inverse?, #limit, #match, #offset, #page, #query_results, #where
Constructor Details
#initialize(base, opts_or_string) ⇒ MatchClause #initialize(base, opts_or_string) ⇒ MatchClause
Creates a new state with a match query applied.
52 53 54 55 56 57 58 59 |
# File 'lib/stretchy/clauses/match_clause.rb', line 52 def initialize(base, opts_or_str = {}, = {}) super(base) if opts_or_str.is_a?(Hash) add_params(.merge(opts_or_str)) else add_params(.merge('_all' => opts_or_str)) end end |
Class Method Details
.tmp(options = {}) ⇒ MatchClause
Creates a temporary MatchClause outside the main query scope by using a new Base. Primarily used in BoostClause for boosting on full-text matches.
23 24 25 26 27 28 29 |
# File 'lib/stretchy/clauses/match_clause.rb', line 23 def self.tmp( = {}) if .delete(:inverse) self.new(Builders::ShellBuilder.new).not() else self.new(Builders::ShellBuilder.new, ) end end |
Instance Method Details
#not(opts_or_str) ⇒ MatchClause #not(opts_or_str) ⇒ MatchClause
Switches to inverted context. Matches applied here work the same way as #initialize, but returned documents must not match these filters.
80 81 82 83 84 |
# File 'lib/stretchy/clauses/match_clause.rb', line 80 def not(opts_or_str = {}) @inverse = true add_params(opts_or_str) self end |
#should(opts_or_str) ⇒ MatchClause #should(opts_or_str) ⇒ MatchClause
Switches to should
context. Applies full-text matches
that are not required, but boost the relevance score for
matching documents.
Can be chained with #not
119 120 121 122 123 124 |
# File 'lib/stretchy/clauses/match_clause.rb', line 119 def should(opts_or_str = {}) @should = true @inverse = false add_params(opts_or_str) self end |
#should? ⇒ true, false
Accessor for @should
148 149 150 |
# File 'lib/stretchy/clauses/match_clause.rb', line 148 def should? !!@should end |
#to_boost(weight = nil) ⇒ Stretchy::Boosts::FilterBoost
Converts this match context to a set of boosts to use in a Queries::FunctionScoreQuery
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/stretchy/clauses/match_clause.rb', line 133 def to_boost(weight = nil) weight ||= Stretchy::Boosts::FilterBoost::DEFAULT_WEIGHT Stretchy::Boosts::FilterBoost.new( filter: Stretchy::Filters::QueryFilter.new( base.match_builder.to_query ), weight: weight ) end |