Class: Gcloud::Search::Result::List

Inherits:
Array
  • Object
show all
Defined in:
lib/gcloud/search/result/list.rb

Overview

Result::List is a special case Array with additional values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr = []) ⇒ List

Create a new Result::List with an array of Gcloud::Search::Result instances.


36
37
38
# File 'lib/gcloud/search/result/list.rb', line 36

def initialize arr = []
  super arr
end

Instance Attribute Details

#matched_countObject (readonly)

The number of documents that match the query. It is greater than or equal to the number of documents actually returned. This is an approximation and not an exact count unless it is less than or equal to the Index#search matched_count_accuracy option.


32
33
34
# File 'lib/gcloud/search/result/list.rb', line 32

def matched_count
  @matched_count
end

#tokenObject (readonly)

If not empty, indicates that there are more records that match the request and this value should be passed to continue.


25
26
27
# File 'lib/gcloud/search/result/list.rb', line 25

def token
  @token
end

Instance Method Details

#allObject

Retrieves all results by repeatedly loading pages until #next? returns false. Returns the list instance for method chaining.


57
58
59
60
61
62
63
64
# File 'lib/gcloud/search/result/list.rb', line 57

def all
  while next?
    next_results = self.next
    push(*next_results)
    self.token = next_results.token
  end
  self
end

#nextObject

Retrieve the next page of results.


48
49
50
51
52
# File 'lib/gcloud/search/result/list.rb', line 48

def next
  return nil unless next?
  ensure_index!
  @index.search @query, @search_options.merge(token: token)
end

#next?Boolean

Whether there a next page of results.


42
43
44
# File 'lib/gcloud/search/result/list.rb', line 42

def next?
  !token.nil?
end