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.
-
#initialize(base) ⇒ BoostClause
constructor
Switch to the boost state, specifying that the next where / range / etc will be a boost instead of a regular filter / range / etc.
-
#match(options = {}) ⇒ BoostMatchClause
(also: #fulltext)
Changes query state to "match" in the context of boosting.
-
#max(num) ⇒ self
The maximum boost that any document can have.
-
#near(options = {}) ⇒ Base
(also: #geo)
Adds a Boosts::FieldDecayBoost, which boosts a search result based on how close it is to a specified value.
- #not(options = {}) ⇒ BoostClause
-
#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(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, #inverse?, #limit, #offset, #page, #query_results, #should
Constructor Details
#initialize(base) ⇒ BoostClause
Switch to the boost state, specifying that the next where / range / etc will be a boost instead of a regular filter / range / etc.
34 35 36 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 34 def initialize(base) super(base) end |
Instance Method Details
#all(num) ⇒ self
Defines a global boost for all documents in the query
154 155 156 157 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 154 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.
189 190 191 192 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 189 def boost_mode(mode) base.boost_builder.boost_mode = mode self end |
#match(options = {}) ⇒ BoostMatchClause Also known as: fulltext
Changes query state to "match" in the context of boosting. Options here work the same way as MatchClause#initialize, but the combined query will be applied as a boost function.
47 48 49 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 47 def match( = {}) BoostMatchClause.new(base, ) end |
#max(num) ⇒ self
The maximum boost that any document can have
165 166 167 168 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 165 def max(num) base.boost_builder.max_boost = num self end |
#near(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
:origin
or:lat
&:lng
combo:scale
122 123 124 125 126 127 128 129 130 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 122 def near( = {}) if [:lat] || [:latitude] || [:lng] || [:longitude] || [:lon] [:origin] = Stretchy::Types::GeoPoint.new() end base.boost_builder.functions << Stretchy::Boosts::FieldDecayBoost.new() Base.new(base) end |
#not(options = {}) ⇒ BoostClause
200 201 202 203 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 200 def not( = {}) @inverse = true self end |
#random(*args) ⇒ Base
Adds a Boosts::RandomBoost to the query, for slightly randomizing search results.
143 144 145 146 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 143 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.
177 178 179 180 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 177 def score_mode(mode) base.boost_builder.score_mode = mode self end |
#where(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.
62 63 64 |
# File 'lib/stretchy/clauses/boost_clause.rb', line 62 def where( = {}) BoostWhereClause.new(base, ) end |