Class: Stretchy::Clauses::BoostClause
- Extended by:
- Forwardable
- Defined in:
- lib/stretchy/clauses/boost_clause.rb
Overview
A Boost clause encapsulates the boost query state. It basically says "the next where / range / match filter will be used to boost a document's score instead of selecting documents to return."
Calling .boost by itself doesn't do anything, but
the next method (.near, .match, etc) will specify
a boost using the same syntax as other clauses. These
methods take a :weight parameter specifying the weight
to assign that boost.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#all(num) ⇒ self
Defines a global boost for all documents in the query.
-
#boost_mode(mode) ⇒ self
Set boost mode for when a document matches multiple boost functions.
-
#field(*args) ⇒ self
Adds a boost based on the value in the specified field.
-
#match(params = {}, options = {}) ⇒ BoostMatchClause
Changes query state to "match" in the context of boosting.
-
#max(num) ⇒ self
The maximum boost that any document can have.
-
#near(params = {}, options = {}) ⇒ Base
(also: #geo)
Adds a Boosts::FieldDecayBoost, which boosts a search result based on how close it is to a specified value.
- #not(*args) ⇒ Object
-
#random(*args) ⇒ Base
Adds a Boosts::RandomBoost to the query, for slightly randomizing search results.
-
#score_mode(mode) ⇒ self
Set scoring mode for when a document matches multiple boost functions.
-
#where(params = {}, options = {}) ⇒ BoostWhereClause
(also: #filter)
Changes query state to "where" in the context of boosting.
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, #should
Constructor Details
This class inherits a constructor from Stretchy::Clauses::Base
Instance Method Details
#all(num) ⇒ self
Defines a global boost for all documents in the query
175 176 177 178 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 175 def all(num) base.boost_builder.overall_boost = num self end |
#boost_mode(mode) ⇒ self
Set boost mode for when a document matches multiple boost functions.
210 211 212 213 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 210 def boost_mode(mode) base.boost_builder.boost_mode = mode self end |
#field(*args) ⇒ self
Adds a boost based on the value in the specified field.
You can pass more than one field as arguments, and
you can also pass the factor and modifier options
as an options hash.
CAUTION: All documents in the index must have a numeric value for any fields specified here, or the query will fail.
76 77 78 79 80 81 82 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 76 def field(*args) = args.last.is_a?(Hash) ? args.pop : {} args.each do |field| base.boost_builder.add_boost(Boosts::FieldValueBoost.new(field, )) end Base.new(base) end |
#match(params = {}, options = {}) ⇒ BoostMatchClause
Changes query state to "match" in the context of boosting. Options here work the same way as Stretchy::Clauses::Base#initialize, but the combined query will be applied as a boost function.
34 35 36 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 34 def match(params = {}, = {}) BoostMatchClause.new(base).boost_match(params, ) end |
#max(num) ⇒ self
The maximum boost that any document can have
186 187 188 189 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 186 def max(num) base.boost_builder.max_boost = num self end |
#near(params = {}, options = {}) ⇒ Base Also known as: geo
Adds a Boosts::FieldDecayBoost, which boosts a search result based on how close it is to a specified value. That value can be a date, time, number, or Types::GeoPoint
Required:
:field:originor:lat&:lngcombo:scale
143 144 145 146 147 148 149 150 151 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 143 def near(params = {}, = {}) if params[:lat] || params[:latitude] || params[:lng] || params[:longitude] || params[:lon] params[:origin] = Stretchy::Types::GeoPoint.new(params) end base.boost_builder.add_boost Stretchy::Boosts::FieldDecayBoost.new(params) Base.new(base) end |
#not(*args) ⇒ Object
84 85 86 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 84 def not(*args) raise Errors::InvalidQueryError.new("Cannot call .not directly after boost - use .where.not or .match.not instead") end |
#random(*args) ⇒ Base
Adds a Boosts::RandomBoost to the query, for slightly randomizing search results.
164 165 166 167 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 164 def random(*args) base.boost_builder.functions << Stretchy::Boosts::RandomBoost.new(*args) Base.new(base) end |
#score_mode(mode) ⇒ self
Set scoring mode for when a document matches multiple boost functions.
198 199 200 201 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 198 def score_mode(mode) base.boost_builder.score_mode = mode self end |
#where(params = {}, options = {}) ⇒ BoostWhereClause Also known as: filter
Changes query state to "where" in the context of boosting. Works the same way as WhereClause, but applies the generated filters as a boost function.
48 49 50 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 48 def where(params = {}, = {}) BoostWhereClause.new(base).boost_where(params, ) end |