Class: Stretchy::Clauses::BoostWhereClause

Inherits:
BoostClause show all
Defined in:
lib/stretchy/clauses/boost_where_clause.rb

Overview

Boosts documents that match certain filters. Most filters will be passed into #initialize, but you can also use .range and .geo .

Author:

  • [atevans]

Instance Attribute Summary

Attributes inherited from Base

#base

Instance Method Summary collapse

Methods inherited from BoostClause

#all, #boost_mode, #max, #near, #not, #random, #score_mode

Methods inherited from Base

#aggregations, #boost, #explain, #fields, #get_aggregations, #get_explain, #get_fields, #get_limit, #get_offset, #get_page, #inverse?, #limit, #not, #offset, #page, #query_results, #should

Constructor Details

#initialize(base, options = {}) ⇒ BoostWhereClause

Generates a boost that matches a set of filters.

Parameters:

  • base (Base)

    Query to copy data from.

  • options (defaults to: {})

    = {} [Hash] Fields and values to filter on.

See Also:

  • Stretchy::Clauses::BoostWhereClause.{WhereClause{WhereClause#initialize}


23
24
25
26
27
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 23

def initialize(base, options = {})
  super(base)
  where_function(:init, options) if options.any?
  self
end

Instance Method Details

#geo(*args) ⇒ 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.

Returns:

  • (Base)

    Query in base context with geo filter boost applied

See Also:

  • Stretchy::Clauses::BoostWhereClause.{WhereFunction{WhereFunction#geo}
  • Stretchy::Clauses::BoostWhereClause.{Filters{Filters::GeoFilter}
  • Elastic Docs - Geo Distance Filter


94
95
96
97
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 94

def geo(*args)
  where_function(:geo, *args)
  Base.new(base)
end

#match(*args) ⇒ MatchClause

Returns to the base context. Queries passed here will be used to filter documents.

Examples:

Returning to base context

query.boost.where(number_field: 89).match('username')

Staying in boost context

query.boost.where(number_field: 89).boost.match('love')

Returns:

  • (MatchClause)

    Base context with match queries applied

See Also:

  • Stretchy::Clauses::BoostWhereClause.{MatchClause{MatchClause#initialize}


59
60
61
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 59

def match(*args)
  MatchClause.new(base, *args)
end

#range(*args) ⇒ Base

Applies a range filter with a min or max as a boost.

Returns:

  • (Base)

    Query in base context with range boost applied

See Also:

  • Stretchy::Clauses::BoostWhereClause.{WhereClause{WhereClause#range}
  • Stretchy::Clauses::BoostWhereClause.{Filters{Filters::RangeFilter}
  • Elastic Guides - Ranges


74
75
76
77
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 74

def range(*args)
  where_function(:range, *args)
  Base.new(base)
end

#where(*args) ⇒ WhereClause

Returns to the base context; filters passed here will be used to filter documents.

Examples:

Returning to base context

query.boost.where(number_field: 33).where(other_field: 64)

Staying in boost context

query.boost.where(number_field: 33).boost.where(other_field: 99)

Returns:

See Also:

  • Stretchy::Clauses::BoostWhereClause.{WhereClause{WhereClause#initialize}


42
43
44
# File 'lib/stretchy/clauses/boost_where_clause.rb', line 42

def where(*args)
  WhereClause.new(base, *args)
end