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

Inherits:
Object
  • Object
show all
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 collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, **kwargs) ⇒ CombineResultsMethod

Returns a new instance of CombineResultsMethod.

Parameters:



164
165
166
167
# 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) (defaults to: nil)

    the weight of the first leg

  • beta (Numeric, nil) (defaults to: nil)

    the weight of the second leg

Returns:



197
198
199
200
201
202
203
# 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) (defaults to: nil)

    the WINDOW size

  • constant (Numeric, nil) (defaults to: nil)

    the CONSTANT value

Returns:



183
184
185
186
187
188
189
190
# 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 the COMBINE argument tokens, beginning with "COMBINE".

Returns:

  • (Array<String>)

    the COMBINE argument tokens, beginning with "COMBINE"



170
171
172
173
174
175
176
# 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