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.
Constant Summary collapse
- FULLTEXT_SLOP =
50- FULLTEXT_MIN =
1
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#fulltext(params = {}) ⇒ self
Specifies that values for this field should be matched with a proximity boost, rather than as a generic match query.
- #match(params = {}, options = {}) ⇒ Object
-
#more_like(params = {}, options = {}) ⇒ MatchClause
Adds a MoreLikeThis query to the chain.
-
#not(params = {}, options = {}) ⇒ MatchClause
Switches to inverted context.
-
#should(params = {}, options = {}) ⇒ MatchClause
Switches to
shouldcontext. -
#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, #initialize, #inverse?, #limit, #offset, #page, #query_results, #root
Constructor Details
This class inherits a constructor from Stretchy::Clauses::Base
Instance Method Details
#phrase(params) ⇒ self #phrase(params) ⇒ self
Specifies that values for this field should be matched with a proximity boost, rather than as a generic match query.
This means searching for "quick brown fox" will return matches in the following order:
- "the quick brown fox jumped over"
- "the brown quick fox jumped over"
- "the fox, brown & quick jumped over"
- "the quick fox jumped over"
- "the quick green and purple sparkly fox jumped over"
- "the quick dog jumped over"
- "the adoreable puppy jumped over" not returned
56 57 58 59 60 |
# File 'lib/stretchy/clauses/match_clause.rb', line 56 def fulltext(params = {}) add_params(params) add_params(params, should: true, slop: FULLTEXT_SLOP) self end |
#match(params = {}, options = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/stretchy/clauses/match_clause.rb', line 17 def match(params = {}, = {}) @inverse = false unless should? add_params(hashify_params(params), ) self end |
#more_like(params = {}, options = {}) ⇒ MatchClause
Adds a MoreLikeThis query to the chain. Pass in document ids, an array of index/name/ids, or a string to get documents that have similar terms.
This method accepts all the options in the Elasticsearch
more_like_this query, which are pretty extensive. See the
documentation (link below) to get an idea of what is available.
Only one of :docs, :ids, or :like_text is required, and
one of those three must be present.
98 99 100 101 102 103 104 105 |
# File 'lib/stretchy/clauses/match_clause.rb', line 98 def more_like(params = {}, = {}) query = Queries::MoreLikeThisQuery.new(params) [:inverse] = true if inverse? [:should] = true if should? base.add_query(query, ) self end |
#not(params) ⇒ MatchClause #not(params) ⇒ MatchClause
Switches to inverted context. Matches applied here work the same way as Base#initialize, but returned documents must not match these filters.
126 127 128 129 130 |
# File 'lib/stretchy/clauses/match_clause.rb', line 126 def not(params = {}, = {}) @inverse = true add_params(params, ) self end |
#should(params) ⇒ MatchClause #should(params) ⇒ 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
162 163 164 165 166 167 |
# File 'lib/stretchy/clauses/match_clause.rb', line 162 def should(params = {}, = {}) @should = true @inverse = false add_params(params, ) self end |
#should? ⇒ true, false
Accessor for @should
191 192 193 |
# File 'lib/stretchy/clauses/match_clause.rb', line 191 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
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/stretchy/clauses/match_clause.rb', line 176 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 |