Class: Redis::Commands::Search::SearchResult

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

Overview

Result of FT.SEARCH: the total number of matching documents (which may exceed the number returned because of paging) plus the documents on this page.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total, documents, warnings: []) ⇒ SearchResult

Returns a new instance of SearchResult.

Parameters:

  • total (Integer)

    the total number of matching documents

  • documents (Array<Document>)

    the documents on this page

  • warnings (Array<String>) (defaults to: [])

    any warnings returned by the server



85
86
87
88
89
# File 'lib/redis/commands/modules/search/result.rb', line 85

def initialize(total, documents, warnings: [])
  @total = total
  @documents = documents
  @warnings = warnings
end

Instance Attribute Details

#documentsInteger, ... (readonly)

Returns:

  • (Integer)

    the total number of matching documents (may exceed documents.size because of paging)

  • (Array<Document>)

    the documents on this page

  • (Array<String>)

    any warnings returned by the server (e.g. a query timeout under the return policy); only the RESP3 wire carries warnings on FT.SEARCH, so this is always empty on RESP2 connections



80
81
82
# File 'lib/redis/commands/modules/search/result.rb', line 80

def documents
  @documents
end

#totalInteger, ... (readonly)

Returns:

  • (Integer)

    the total number of matching documents (may exceed documents.size because of paging)

  • (Array<Document>)

    the documents on this page

  • (Array<String>)

    any warnings returned by the server (e.g. a query timeout under the return policy); only the RESP3 wire carries warnings on FT.SEARCH, so this is always empty on RESP2 connections



80
81
82
# File 'lib/redis/commands/modules/search/result.rb', line 80

def total
  @total
end

#warningsInteger, ... (readonly)

Returns:

  • (Integer)

    the total number of matching documents (may exceed documents.size because of paging)

  • (Array<Document>)

    the documents on this page

  • (Array<String>)

    any warnings returned by the server (e.g. a query timeout under the return policy); only the RESP3 wire carries warnings on FT.SEARCH, so this is always empty on RESP2 connections



80
81
82
# File 'lib/redis/commands/modules/search/result.rb', line 80

def warnings
  @warnings
end

Instance Method Details

#[](index) ⇒ Document?

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

Parameters:

  • index (Integer)

    the position within this page

Returns:

  • (Document, nil)

    the document at index, or nil when out of range



101
102
103
# File 'lib/redis/commands/modules/search/result.rb', line 101

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

#each {|document| ... } ⇒ Enumerator, Array<Document>

Iterate over the documents on this page.

Yield Parameters:

Returns:



95
96
97
# File 'lib/redis/commands/modules/search/result.rb', line 95

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

#empty?Boolean

Returns whether this page has no documents.

Returns:

  • (Boolean)

    whether this page has no documents



112
113
114
# File 'lib/redis/commands/modules/search/result.rb', line 112

def empty?
  @documents.empty?
end

#sizeInteger Also known as: length

Returns the number of documents on this page.

Returns:

  • (Integer)

    the number of documents on this page



106
107
108
# File 'lib/redis/commands/modules/search/result.rb', line 106

def size
  @documents.size
end