123456789_123456789_123456789_123456789_123456789_

Class: Redis::Commands::Search::CombineResultsMethod

Relationships & Source Files
Inherits: Object
Defined in: lib/redis/commands/modules/search/hybrid.rb

Overview

The COMBINE clause of an FT.HYBRID query, describing how the two legs' results are fused.

Class Method Summary

Instance Method Summary

Constructor Details

.new(method, **kwargs) ⇒ CombineResultsMethod

Parameters:

  • method (String)

    the combination method (see CombinationMethods)

  • kwargs (Hash)

    the method parameters, emitted as upcased key/value pairs

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/hybrid.rb', line 164

def initialize(method, **kwargs)
  @method = method
  @kwargs = kwargs
end

Class Method Details

.linear(alpha: nil, beta: nil) ⇒ CombineResultsMethod

Build a LINEAR combine method.

Parameters:

  • alpha (Numeric, nil)

    the weight of the first leg

  • beta (Numeric, nil)

    the weight of the second leg

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/hybrid.rb', line 197

def self.linear(alpha: nil, beta: nil)
  # Guard on nil (not truthiness) so alpha/beta of 0 are still emitted.
  kwargs = {}
  kwargs[:alpha] = alpha unless alpha.nil?
  kwargs[:beta] = beta unless beta.nil?
  new(CombinationMethods::LINEAR, **kwargs)
end

.rrf(window: nil, constant: nil) ⇒ CombineResultsMethod

Build a Reciprocal Rank Fusion (+RRF+) combine method.

Parameters:

  • window (Integer, nil)

    the WINDOW size

  • constant (Numeric, nil)

    the CONSTANT value

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/hybrid.rb', line 183

def self.rrf(window: nil, constant: nil)
  # Guard on nil (not truthiness): 0 is a legitimate value and, unlike some languages,
  # truthy in Ruby — but nil-checking keeps "was it provided?" explicit and correct.
  kwargs = {}
  kwargs[:window] = window unless window.nil?
  kwargs[:constant] = constant unless constant.nil?
  new(CombinationMethods::RRF, **kwargs)
end

Instance Method Details

#argsArray<String>

Returns:

  • (Array<String>)

    the COMBINE argument tokens, beginning with "COMBINE"

[ GitHub ]

  
# File 'lib/redis/commands/modules/search/hybrid.rb', line 170

def args
  result = ["COMBINE", @method, (@kwargs.size * 2).to_s]
  @kwargs.each do |key, value|
    result << key.to_s.upcase << value.to_s
  end
  result
end