Class: Gcloud::Search::Result
- Inherits:
-
Object
- Object
- Gcloud::Search::Result
- Defined in:
- lib/gcloud/search/result.rb,
lib/gcloud/search/result/list.rb
Overview
# Result
See Gcloud#search
Defined Under Namespace
Classes: List
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ FieldValue
Retrieve the field values associated to a field name.
-
#doc_id ⇒ String
The unique identifier of the document referenced in the search result.
-
#each(&block) ⇒ Object
Calls block once for each field, passing the field name and values pair as parameters.
-
#fields ⇒ Object
The fields in the search result.
-
#initialize ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
-
#names ⇒ Array<String>
Returns a new array populated with all the field names.
- #to_hash ⇒ Object
-
#token ⇒ String
The token for the next page of results.
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
28 29 30 31 |
# File 'lib/gcloud/search/result.rb', line 28 def initialize @fields = Fields.new @raw = {} end |
Class Method Details
.from_hash(hash) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/gcloud/search/result.rb', line 149 def self.from_hash hash result = new result.instance_variable_set "@raw", hash result.instance_variable_set "@fields", Fields.from_raw(hash["fields"]) result end |
Instance Method Details
#[](name) ⇒ FieldValue
Retrieve the field values associated to a field name.
71 72 73 |
# File 'lib/gcloud/search/result.rb', line 71 def [] name @fields[name] end |
#doc_id ⇒ String
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)
106 107 108 |
# File 'lib/gcloud/search/result.rb', line 106 def each &block @fields.each(&block) end |
#fields ⇒ Object
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 |
#inspect ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/gcloud/search/result.rb', line 136 def inspect insp_token = "" if token trunc_token = "#{token[0, 8]}...#{token[-5..-1]}" trunc_token = token if token.length < 20 insp_token = ", token: #{trunc_token.inspect}" end insp_fields = ", fields: (#{fields.names.map(&:inspect).join ', '})" "#{self.class}(doc_id: #{doc_id.inspect}#{insp_token}#{insp_fields})" end |
#names ⇒ Array<String>
Returns a new array populated with all the field names. (See Fields#names)
130 131 132 |
# File 'lib/gcloud/search/result.rb', line 130 def names @fields.names end |
#to_hash ⇒ Object
158 159 160 161 162 |
# File 'lib/gcloud/search/result.rb', line 158 def to_hash hash = @raw.dup hash["fields"] = @fields.to_raw hash end |
#token ⇒ String
The token for the next page of results.
45 46 47 |
# File 'lib/gcloud/search/result.rb', line 45 def token @raw["nextPageToken"] end |