Class: Stretchy::Clauses::BoostWhereClause
- Inherits:
-
BoostClause
- Object
- Base
- BoostClause
- Stretchy::Clauses::BoostWhereClause
- Defined in:
- lib/stretchy/clauses/boost_where_clause.rb
Overview
Boosts documents that match certain filters. Most filters will
be passed into Stretchy::Clauses::Base#initialize, but you can also use .range
and
.geo
.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #boost_where(params = {}, options = {}) ⇒ Object
-
#geo(field, options = {}) ⇒ Base
Boosts a document if it matches a geo filter.
-
#match(*args) ⇒ MatchClause
Returns to the base context.
- #not(params = {}, options = {}) ⇒ Object
-
#range(field, options = {}) ⇒ Base
Applies a range filter with a min or max as a boost.
-
#where(*args) ⇒ WhereClause
Returns to the base context; filters passed here will be used to filter documents.
Methods inherited from BoostClause
#all, #boost_mode, #field, #max, #near, #random, #score_mode
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
#boost_where(params = {}, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 14 def boost_where(params = {}, = {}) weight = params.delete(:weight) || [:weight] [:inverse] = true if inverse? clause = WhereClause.new.where(params, ) boost = clause.to_boost(weight) base.boost_builder.add_boost(boost) if boost self end |
#geo(field, options = {}) ⇒ Base
Boosts a document if it matches a geo filter.
This is different than Stretchy::Clauses::BoostClause#near -
while .near
applies a decay function that boosts
based on how close a field is to a geo point,
.geo
applies a filter that either boosts or doesn't
boost the document.
99 100 101 102 103 104 105 106 107 |
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 99 def geo(field, = {}) weight = [:weight] [:inverse] = true if inverse? clause = WhereClause.new.geo(field, ) boost = clause.to_boost(weight) base.boost_builder.add_boost(boost) if boost Base.new(base) end |
#match(*args) ⇒ MatchClause
Returns to the base context. Queries passed here will be used to filter documents.
58 59 60 |
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 58 def match(*args) MatchClause.new(base).match(*args) end |
#not(params = {}, options = {}) ⇒ Object
40 41 42 43 |
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 40 def not(params = {}, = {}) @inverse = true boost_where(params, ) end |
#range(field, options = {}) ⇒ Base
Applies a range filter with a min or max as a boost.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 73 def range(field, = {}) weight = [:weight] [:inverse] = true if inverse? clause = WhereClause.new.range(field, ) boost = clause.to_boost(weight) base.boost_builder.add_boost(boost) if boost Base.new(base) end |
#where(*args) ⇒ WhereClause
Returns to the base context; filters passed here will be used to filter documents.
36 37 38 |
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 36 def where(*args) WhereClause.new(base).where(*args) end |