Class: Gcloud::Search::Result

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

Overview

Result

See Gcloud#search

Defined Under Namespace

Classes: List

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ FieldValue

Retrieve the field values associated to a field name.

Examples:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search
index = search.index "products"

documents = index.search "best T-shirt ever"
document = documents.first
puts "The best match for your search is:"
document["description"].each do |value|
  puts "* #{value} (#{value.type}) [#{value.lang}]"
end

71
72
73
# File 'lib/gcloud/search/result.rb', line 71

def [] name
  @fields[name]
end

#doc_idString

The unique identifier of the document referenced in the search result.


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

def doc_id
  @raw["docId"]
end

#each(&block) ⇒ Object

Calls block once for each field, passing the field name and values pair as parameters. If no block is given an enumerator is returned instead. (See Fields#each)

Examples:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search
index = search.index "products"

documents = index.search "best T-shirt ever"
document = documents.first
puts "The best match for your search is:"
document.each do |name, values|
  puts "* #{name}:"
  values.each do |value|
    puts "  * #{value} (#{value.type})"
  end
end

106
107
108
# File 'lib/gcloud/search/result.rb', line 106

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

#fieldsObject

The fields in the search result. Each field has a name (String) and a list of values (FieldValues). (See Fields)


80
81
82
# File 'lib/gcloud/search/result.rb', line 80

def fields
  @fields
end

#namesArray<String>

Returns a new array populated with all the field names. (See Fields#names)

Examples:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search
index = search.index "products"

documents = index.search "best T-shirt ever"
document = documents.first
puts "The best match has the following fields:"
document.names.each do |name|
  puts "* #{name}:"
end

130
131
132
# File 'lib/gcloud/search/result.rb', line 130

def names
  @fields.names
end

#tokenString

The token for the next page of results.


45
46
47
# File 'lib/gcloud/search/result.rb', line 45

def token
  @raw["nextPageToken"]
end