Class: Redis::Commands::Search::HybridResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/redis/commands/modules/search/result.rb

Overview

Result of FT.HYBRID: the fused result rows (each a field => value hash, including the synthetic "__key" and "__score") plus the total, any warnings and the execution time.

When the query used WITHCURSOR the server returns per-leg cursor ids instead of an inline page; those are exposed via #search_cursor / #vsim_cursor and #cursor? is true.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows: [], total: nil, warnings: [], execution_time: nil, search_cursor: nil, vsim_cursor: nil) ⇒ HybridResult

Returns a new instance of HybridResult.



177
178
179
180
181
182
183
184
185
# File 'lib/redis/commands/modules/search/result.rb', line 177

def initialize(rows: [], total: nil, warnings: [], execution_time: nil,
               search_cursor: nil, vsim_cursor: nil)
  @rows = rows
  @total = total
  @warnings = warnings
  @execution_time = execution_time
  @search_cursor = search_cursor
  @vsim_cursor = vsim_cursor
end

Instance Attribute Details

#execution_timeArray<Hash{String => Object}>, ... (readonly)

Returns:

  • (Array<Hash{String => Object}>)

    the fused result rows

  • (Integer, nil)

    the total number of fused results

  • (Array)

    any warnings returned by the server

  • (Float, nil)

    the server-side execution time

  • (Integer, nil)

    the SEARCH-leg cursor id (WITHCURSOR only)

  • (Integer, nil)

    the VSIM-leg cursor id (WITHCURSOR only)



175
176
177
# File 'lib/redis/commands/modules/search/result.rb', line 175

def execution_time
  @execution_time
end

#rowsArray<Hash{String => Object}>, ... (readonly)

Returns:

  • (Array<Hash{String => Object}>)

    the fused result rows

  • (Integer, nil)

    the total number of fused results

  • (Array)

    any warnings returned by the server

  • (Float, nil)

    the server-side execution time

  • (Integer, nil)

    the SEARCH-leg cursor id (WITHCURSOR only)

  • (Integer, nil)

    the VSIM-leg cursor id (WITHCURSOR only)



175
176
177
# File 'lib/redis/commands/modules/search/result.rb', line 175

def rows
  @rows
end

#search_cursorArray<Hash{String => Object}>, ... (readonly)

Returns:

  • (Array<Hash{String => Object}>)

    the fused result rows

  • (Integer, nil)

    the total number of fused results

  • (Array)

    any warnings returned by the server

  • (Float, nil)

    the server-side execution time

  • (Integer, nil)

    the SEARCH-leg cursor id (WITHCURSOR only)

  • (Integer, nil)

    the VSIM-leg cursor id (WITHCURSOR only)



175
176
177
# File 'lib/redis/commands/modules/search/result.rb', line 175

def search_cursor
  @search_cursor
end

#totalArray<Hash{String => Object}>, ... (readonly)

Returns:

  • (Array<Hash{String => Object}>)

    the fused result rows

  • (Integer, nil)

    the total number of fused results

  • (Array)

    any warnings returned by the server

  • (Float, nil)

    the server-side execution time

  • (Integer, nil)

    the SEARCH-leg cursor id (WITHCURSOR only)

  • (Integer, nil)

    the VSIM-leg cursor id (WITHCURSOR only)



175
176
177
# File 'lib/redis/commands/modules/search/result.rb', line 175

def total
  @total
end

#vsim_cursorArray<Hash{String => Object}>, ... (readonly)

Returns:

  • (Array<Hash{String => Object}>)

    the fused result rows

  • (Integer, nil)

    the total number of fused results

  • (Array)

    any warnings returned by the server

  • (Float, nil)

    the server-side execution time

  • (Integer, nil)

    the SEARCH-leg cursor id (WITHCURSOR only)

  • (Integer, nil)

    the VSIM-leg cursor id (WITHCURSOR only)



175
176
177
# File 'lib/redis/commands/modules/search/result.rb', line 175

def vsim_cursor
  @vsim_cursor
end

#warningsArray<Hash{String => Object}>, ... (readonly)

Returns:

  • (Array<Hash{String => Object}>)

    the fused result rows

  • (Integer, nil)

    the total number of fused results

  • (Array)

    any warnings returned by the server

  • (Float, nil)

    the server-side execution time

  • (Integer, nil)

    the SEARCH-leg cursor id (WITHCURSOR only)

  • (Integer, nil)

    the VSIM-leg cursor id (WITHCURSOR only)



175
176
177
# File 'lib/redis/commands/modules/search/result.rb', line 175

def warnings
  @warnings
end

Instance Method Details

#[](index) ⇒ Hash?

Returns the row at index, or nil when out of range.

Parameters:

  • index (Integer)

    the row position

Returns:

  • (Hash, nil)

    the row at index, or nil when out of range



197
198
199
# File 'lib/redis/commands/modules/search/result.rb', line 197

def [](index)
  @rows[index]
end

#cursor?Boolean

Returns whether this is a WITHCURSOR reply carrying cursor ids.

Returns:

  • (Boolean)

    whether this is a WITHCURSOR reply carrying cursor ids



213
214
215
# File 'lib/redis/commands/modules/search/result.rb', line 213

def cursor?
  !@search_cursor.nil? || !@vsim_cursor.nil?
end

#each {|row| ... } ⇒ Enumerator, Array<Hash>

Iterate over the result rows.

Yield Parameters:

  • row (Hash{String => Object})

Returns:

  • (Enumerator, Array<Hash>)


191
192
193
# File 'lib/redis/commands/modules/search/result.rb', line 191

def each(&block)
  @rows.each(&block)
end

#empty?Boolean

Returns whether there are no rows.

Returns:

  • (Boolean)

    whether there are no rows



208
209
210
# File 'lib/redis/commands/modules/search/result.rb', line 208

def empty?
  @rows.empty?
end

#sizeInteger Also known as: length

Returns the number of rows.

Returns:

  • (Integer)

    the number of rows



202
203
204
# File 'lib/redis/commands/modules/search/result.rb', line 202

def size
  @rows.size
end