Class: Redis::Commands::Search::AggregateResult

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

Overview

Result of FT.AGGREGATE (and FT.CURSOR READ): the rows produced by the pipeline plus, when WITHCURSOR was requested, the cursor id to read the next batch with (0 when the cursor is exhausted).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows, cursor: nil) ⇒ AggregateResult

Returns a new instance of AggregateResult.

Parameters:

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

    the pipeline rows

  • cursor (Integer, nil) (defaults to: nil)

    the next cursor id, or nil when no cursor was requested



130
131
132
133
# File 'lib/redis/commands/modules/search/result.rb', line 130

def initialize(rows, cursor: nil)
  @rows = rows
  @cursor = cursor
end

Instance Attribute Details

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

Returns:

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

    the rows produced by the pipeline, each a field => value hash

  • (Integer, nil)

    the next cursor id (0 when exhausted), or nil when no cursor



126
127
128
# File 'lib/redis/commands/modules/search/result.rb', line 126

def cursor
  @cursor
end

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

Returns:

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

    the rows produced by the pipeline, each a field => value hash

  • (Integer, nil)

    the next cursor id (0 when exhausted), or nil when no cursor



126
127
128
# File 'lib/redis/commands/modules/search/result.rb', line 126

def rows
  @rows
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



145
146
147
# File 'lib/redis/commands/modules/search/result.rb', line 145

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

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

Iterate over the rows.

Yield Parameters:

  • row (Hash{String => Object})

Returns:

  • (Enumerator, Array<Hash>)


139
140
141
# File 'lib/redis/commands/modules/search/result.rb', line 139

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

#empty?Boolean

Returns whether there are no rows.

Returns:

  • (Boolean)

    whether there are no rows



156
157
158
# File 'lib/redis/commands/modules/search/result.rb', line 156

def empty?
  @rows.empty?
end

#sizeInteger Also known as: length

Returns the number of rows.

Returns:

  • (Integer)

    the number of rows



150
151
152
# File 'lib/redis/commands/modules/search/result.rb', line 150

def size
  @rows.size
end