Class: Stretchy::Clauses::BoostMatchClause

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

Overview

Boost documents that match a free-text query. Most options will be passed into Stretchy::Clauses::Base#initialize, but you can also chain .not onto it. Calling .where or .match from here will apply filters (not boosts) and return to the base state

Author:

  • [atevans]

Instance Attribute Summary

Attributes inherited from Base

#base

Instance Method Summary collapse

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_match(params = {}, options = {}) ⇒ Object



35
36
37
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 35

def boost_match(params = {}, options = {})
  match_function(hashify_params(params), options)
end

#fulltext(params = {}, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 39

def fulltext(params = {}, options = {})
  _params = hashify_params(params)
  weight = _params.delete(:weight) || options[:weight]
  options[:min]  ||= MatchClause::FULLTEXT_MIN
  options[:slop] ||= MatchClause::FULLTEXT_SLOP
  options[:type] ||= Queries::MatchQuery::MATCH_TYPES.first
  clause = MatchClause.new.match(_params, options)
  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.

Examples:

Returning to base context

query.boost.match(message: 'curse word').match('username')

Staying in boost context

query.boost.match(message: 'happy word').boost.match('love')

Returns:

  • (MatchClause)

    Base context with match queries applied

See Also:

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


81
82
83
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 81

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

#not(params) ⇒ BoostMatchClause #not(params) ⇒ BoostMatchClause

Switches to inverse context, and applies filters as inverse options (ie, documents that do not match the query will be boosted)

Overloads:

  • #not(params) ⇒ BoostMatchClause

    Parameters:

    • String (String)

      that must not match anywhere in the document

  • #not(params) ⇒ BoostMatchClause

    Parameters:

    • params (Hash)

      Fields and values that should not match in the document

Returns:



30
31
32
33
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 30

def not(params = {})
  @inverse = true
  match_function(hashify_params(params))
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.match('string').where(other_field: 64)

Staying in boost context

query.boost.match('string').boost.where(other_field: 99)

Returns:

See Also:

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


64
65
66
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 64

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