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 #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, #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, #inverse?, #limit, #offset, #page, #query_results, #should

Constructor Details

#initialize(base, opts_or_string) ⇒ BoostMatchClause #initialize(base, opts_or_string) ⇒ BoostMatchClause

Adds a match query to the boost functions.

Overloads:

  • #initialize(base, opts_or_string) ⇒ BoostMatchClause

    Parameters:

    • base (Base)

      Base query to copy data from

    • opts_or_string (String)

      String to do a free-text match across the document

  • #initialize(base, opts_or_string) ⇒ BoostMatchClause

    Parameters:

    • base (Base)

      Base query to copy data from

    • options

      = {} [Hash] Fields and values to match via full-text search



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

def initialize(base, opts_or_string = {}, options = {})
  super(base)
  if opts_or_string.is_a?(Hash)
    match_function(opts_or_string.merge(options))
  else
    match_function(options.merge('_all' => opts_or_string))
  end
end

Instance Method Details

#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}


91
92
93
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 91

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

#not(opts_or_string) ⇒ BoostMatchClause #not(opts_or_string) ⇒ BoostMatchClause

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

Overloads:

  • #not(opts_or_string) ⇒ BoostMatchClause

    Parameters:

    • String (String)

      that must not match anywhere in the document

  • #not(opts_or_string) ⇒ BoostMatchClause

    Parameters:

    • opts_or_string (Hash)

      Fields and values that should not match in the document

Returns:



51
52
53
54
55
56
57
58
59
# File 'lib/stretchy/clauses/boost_match_clause.rb', line 51

def not(opts_or_string = {})
  @inverse = true
  if opts_or_string.is_a?(Hash)
    match_function(opts_or_string)
  else
    match_function('_all' => opts_or_string)
  end
  self
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}


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

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