gcloud 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/AUTHENTICATION.md +13 -9
- data/CHANGELOG.md +8 -3
- data/OVERVIEW.md +46 -8
- data/lib/gcloud.rb +123 -117
- data/lib/gcloud/backoff.rb +43 -15
- data/lib/gcloud/bigquery.rb +211 -195
- data/lib/gcloud/bigquery/connection.rb +9 -9
- data/lib/gcloud/bigquery/copy_job.rb +15 -16
- data/lib/gcloud/bigquery/credentials.rb +3 -3
- data/lib/gcloud/bigquery/data.rb +12 -11
- data/lib/gcloud/bigquery/dataset.rb +162 -216
- data/lib/gcloud/bigquery/dataset/access.rb +59 -43
- data/lib/gcloud/bigquery/dataset/list.rb +3 -3
- data/lib/gcloud/bigquery/errors.rb +9 -5
- data/lib/gcloud/bigquery/extract_job.rb +18 -18
- data/lib/gcloud/bigquery/insert_response.rb +7 -4
- data/lib/gcloud/bigquery/job.rb +48 -44
- data/lib/gcloud/bigquery/job/list.rb +3 -3
- data/lib/gcloud/bigquery/load_job.rb +24 -25
- data/lib/gcloud/bigquery/project.rb +145 -204
- data/lib/gcloud/bigquery/query_data.rb +10 -9
- data/lib/gcloud/bigquery/query_job.rb +23 -32
- data/lib/gcloud/bigquery/table.rb +238 -280
- data/lib/gcloud/bigquery/table/list.rb +3 -3
- data/lib/gcloud/bigquery/table/schema.rb +79 -87
- data/lib/gcloud/bigquery/view.rb +69 -82
- data/lib/gcloud/credentials.rb +3 -9
- data/lib/gcloud/datastore.rb +194 -170
- data/lib/gcloud/datastore/connection.rb +12 -8
- data/lib/gcloud/datastore/credentials.rb +6 -4
- data/lib/gcloud/datastore/dataset.rb +74 -141
- data/lib/gcloud/datastore/dataset/lookup_results.rb +6 -4
- data/lib/gcloud/datastore/dataset/query_results.rb +6 -4
- data/lib/gcloud/datastore/entity.rb +81 -76
- data/lib/gcloud/datastore/errors.rb +10 -8
- data/lib/gcloud/datastore/key.rb +41 -77
- data/lib/gcloud/datastore/properties.rb +3 -3
- data/lib/gcloud/datastore/proto.rb +7 -4
- data/lib/gcloud/datastore/query.rb +26 -3
- data/lib/gcloud/datastore/transaction.rb +12 -8
- data/lib/gcloud/dns.rb +180 -152
- data/lib/gcloud/dns/change.rb +16 -16
- data/lib/gcloud/dns/change/list.rb +3 -3
- data/lib/gcloud/dns/connection.rb +9 -10
- data/lib/gcloud/dns/credentials.rb +3 -3
- data/lib/gcloud/dns/errors.rb +9 -5
- data/lib/gcloud/dns/importer.rb +17 -23
- data/lib/gcloud/dns/project.rb +42 -64
- data/lib/gcloud/dns/record.rb +58 -46
- data/lib/gcloud/dns/record/list.rb +6 -7
- data/lib/gcloud/dns/zone.rb +198 -289
- data/lib/gcloud/dns/zone/list.rb +3 -3
- data/lib/gcloud/dns/zone/transaction.rb +56 -72
- data/lib/gcloud/errors.rb +174 -3
- data/lib/gcloud/gce.rb +3 -4
- data/lib/gcloud/grpc_utils.rb +76 -0
- data/lib/gcloud/logging.rb +308 -0
- data/lib/gcloud/logging/credentials.rb +29 -0
- data/lib/gcloud/logging/entry.rb +303 -0
- data/lib/gcloud/logging/entry/http_request.rb +141 -0
- data/lib/gcloud/logging/entry/list.rb +111 -0
- data/lib/gcloud/logging/entry/operation.rb +90 -0
- data/lib/gcloud/logging/logger.rb +307 -0
- data/lib/gcloud/logging/metric.rb +175 -0
- data/lib/gcloud/logging/metric/list.rb +98 -0
- data/lib/gcloud/logging/project.rb +650 -0
- data/lib/gcloud/logging/resource.rb +95 -0
- data/lib/gcloud/logging/resource_descriptor.rb +140 -0
- data/lib/gcloud/logging/resource_descriptor/list.rb +78 -0
- data/lib/gcloud/logging/service.rb +258 -0
- data/lib/gcloud/logging/sink.rb +233 -0
- data/lib/gcloud/logging/sink/list.rb +97 -0
- data/lib/gcloud/pubsub.rb +241 -199
- data/lib/gcloud/pubsub/credentials.rb +3 -3
- data/lib/gcloud/pubsub/message.rb +26 -20
- data/lib/gcloud/pubsub/project.rb +166 -233
- data/lib/gcloud/pubsub/received_message.rb +28 -38
- data/lib/gcloud/pubsub/service.rb +323 -0
- data/lib/gcloud/pubsub/subscription.rb +172 -242
- data/lib/gcloud/pubsub/subscription/list.rb +11 -9
- data/lib/gcloud/pubsub/topic.rb +152 -271
- data/lib/gcloud/pubsub/topic/batch.rb +66 -0
- data/lib/gcloud/pubsub/topic/list.rb +9 -7
- data/lib/gcloud/resource_manager.rb +158 -138
- data/lib/gcloud/resource_manager/connection.rb +6 -5
- data/lib/gcloud/resource_manager/credentials.rb +3 -3
- data/lib/gcloud/resource_manager/errors.rb +9 -5
- data/lib/gcloud/resource_manager/manager.rb +54 -86
- data/lib/gcloud/resource_manager/project.rb +69 -88
- data/lib/gcloud/resource_manager/project/list.rb +4 -5
- data/lib/gcloud/resource_manager/project/updater.rb +12 -14
- data/lib/gcloud/search.rb +158 -135
- data/lib/gcloud/search/api_client.rb +7 -7
- data/lib/gcloud/search/connection.rb +8 -8
- data/lib/gcloud/search/credentials.rb +3 -3
- data/lib/gcloud/search/document.rb +64 -87
- data/lib/gcloud/search/document/list.rb +5 -5
- data/lib/gcloud/search/errors.rb +9 -5
- data/lib/gcloud/search/field_value.rb +32 -38
- data/lib/gcloud/search/field_values.rb +50 -80
- data/lib/gcloud/search/fields.rb +44 -65
- data/lib/gcloud/search/index.rb +163 -204
- data/lib/gcloud/search/index/list.rb +5 -5
- data/lib/gcloud/search/project.rb +31 -47
- data/lib/gcloud/search/result.rb +27 -31
- data/lib/gcloud/search/result/list.rb +6 -6
- data/lib/gcloud/storage.rb +224 -190
- data/lib/gcloud/storage/bucket.rb +202 -227
- data/lib/gcloud/storage/bucket/acl.rb +83 -170
- data/lib/gcloud/storage/bucket/cors.rb +31 -34
- data/lib/gcloud/storage/bucket/list.rb +3 -3
- data/lib/gcloud/storage/connection.rb +11 -7
- data/lib/gcloud/storage/credentials.rb +3 -3
- data/lib/gcloud/storage/errors.rb +11 -8
- data/lib/gcloud/storage/file.rb +129 -171
- data/lib/gcloud/storage/file/acl.rb +51 -99
- data/lib/gcloud/storage/file/list.rb +3 -3
- data/lib/gcloud/storage/file/verifier.rb +3 -2
- data/lib/gcloud/storage/project.rb +111 -132
- data/lib/gcloud/upload.rb +4 -7
- data/lib/gcloud/version.rb +2 -4
- data/lib/google/api/annotations.rb +14 -0
- data/lib/google/api/http.rb +30 -0
- data/lib/google/api/label.rb +24 -0
- data/lib/google/api/monitored_resource.rb +25 -0
- data/lib/google/datastore/v1beta3/datastore.rb +115 -0
- data/lib/google/datastore/v1beta3/datastore_services.rb +33 -0
- data/lib/google/datastore/v1beta3/entity.rb +63 -0
- data/lib/google/datastore/v1beta3/query.rb +128 -0
- data/lib/google/devtools/cloudtrace/v1/trace.rb +78 -0
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +32 -0
- data/lib/google/example/library/v1/library.rb +91 -0
- data/lib/google/example/library/v1/library_services.rb +40 -0
- data/lib/google/iam/v1/iam_policy.rb +33 -0
- data/lib/google/iam/v1/iam_policy_services.rb +30 -0
- data/lib/google/iam/v1/policy.rb +25 -0
- data/lib/google/logging/type/http_request.rb +28 -0
- data/lib/google/logging/type/log_severity.rb +27 -0
- data/lib/google/logging/v2/log_entry.rb +44 -0
- data/lib/google/logging/v2/logging.rb +56 -0
- data/lib/google/logging/v2/logging_config.rb +59 -0
- data/lib/google/logging/v2/logging_config_services.rb +32 -0
- data/lib/google/logging/v2/logging_metrics.rb +51 -0
- data/lib/google/logging/v2/logging_metrics_services.rb +32 -0
- data/lib/google/logging/v2/logging_services.rb +31 -0
- data/lib/google/longrunning/operations.rb +50 -0
- data/lib/google/longrunning/operations_services.rb +29 -0
- data/lib/google/protobuf/any.rb +17 -0
- data/lib/google/protobuf/api.rb +31 -0
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/protobuf/duration.rb +17 -0
- data/lib/google/protobuf/empty.rb +15 -0
- data/lib/google/protobuf/field_mask.rb +16 -0
- data/lib/google/protobuf/source_context.rb +16 -0
- data/lib/google/protobuf/struct.rb +35 -0
- data/lib/google/protobuf/timestamp.rb +17 -0
- data/lib/google/protobuf/type.rb +79 -0
- data/lib/google/protobuf/wrappers.rb +48 -0
- data/lib/google/pubsub/v1/pubsub.rb +129 -0
- data/lib/google/pubsub/v1/pubsub_services.rb +56 -0
- data/lib/google/pubsub/v1beta2/pubsub.rb +126 -0
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +56 -0
- data/lib/google/rpc/code.rb +32 -0
- data/lib/google/rpc/error_details.rb +61 -0
- data/lib/google/rpc/status.rb +19 -0
- data/lib/google/type/color.rb +20 -0
- data/lib/google/type/date.rb +18 -0
- data/lib/google/type/dayofweek.rb +23 -0
- data/lib/google/type/latlng.rb +17 -0
- data/lib/google/type/money.rb +18 -0
- data/lib/google/type/timeofday.rb +19 -0
- metadata +101 -4
- data/lib/gcloud/pubsub/connection.rb +0 -295
- data/lib/gcloud/pubsub/errors.rb +0 -93
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2015 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,6 +12,7 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
module Gcloud
|
17
17
|
module ResourceManager
|
18
18
|
class Project
|
@@ -48,8 +48,7 @@ module Gcloud
|
|
48
48
|
# Retrieves all projects by repeatedly loading pages until #next?
|
49
49
|
# returns false. Returns the list instance for method chaining.
|
50
50
|
#
|
51
|
-
#
|
52
|
-
#
|
51
|
+
# @example
|
53
52
|
# require "gcloud"
|
54
53
|
#
|
55
54
|
# gcloud = Gcloud.new
|
@@ -66,8 +65,8 @@ module Gcloud
|
|
66
65
|
end
|
67
66
|
|
68
67
|
##
|
69
|
-
# New Projects::List from a response object.
|
70
|
-
def self.from_response resp, manager
|
68
|
+
# @private New Projects::List from a response object.
|
69
|
+
def self.from_response resp, manager
|
71
70
|
projects = new(Array(resp.data["projects"]).map do |gapi_object|
|
72
71
|
Project.from_gapi gapi_object, manager.connection
|
73
72
|
end)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2015 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,6 +12,7 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "time"
|
17
17
|
require "gcloud/resource_manager/errors"
|
18
18
|
|
@@ -20,11 +20,12 @@ module Gcloud
|
|
20
20
|
module ResourceManager
|
21
21
|
class Project
|
22
22
|
##
|
23
|
-
#
|
23
|
+
# # Project Updater
|
24
24
|
#
|
25
25
|
# This object is used by Project#update when passed a block. These methods
|
26
26
|
# are used to update the project data in a single API call.
|
27
27
|
#
|
28
|
+
# @example
|
28
29
|
# require "gcloud"
|
29
30
|
#
|
30
31
|
# gcloud = Gcloud.new
|
@@ -37,8 +38,8 @@ module Gcloud
|
|
37
38
|
#
|
38
39
|
class Updater < DelegateClass(Project)
|
39
40
|
##
|
40
|
-
# Create an Updater object.
|
41
|
-
def initialize project
|
41
|
+
# @private Create an Updater object.
|
42
|
+
def initialize project
|
42
43
|
super project
|
43
44
|
end
|
44
45
|
|
@@ -49,8 +50,7 @@ module Gcloud
|
|
49
50
|
# Allowed characters are: lowercase and uppercase letters, numbers,
|
50
51
|
# hyphen, single-quote, double-quote, space, and exclamation point.
|
51
52
|
#
|
52
|
-
#
|
53
|
-
#
|
53
|
+
# @example
|
54
54
|
# require "gcloud"
|
55
55
|
#
|
56
56
|
# gcloud = Gcloud.new
|
@@ -75,10 +75,9 @@ module Gcloud
|
|
75
75
|
# to the regular expression <code>([a-z]([-a-z0-9]*[a-z0-9])?)?</code>.
|
76
76
|
#
|
77
77
|
# No more than 256 labels can be associated with a given resource.
|
78
|
-
# (
|
79
|
-
#
|
80
|
-
# === Example
|
78
|
+
# (`Hash`)
|
81
79
|
#
|
80
|
+
# @example
|
82
81
|
# require "gcloud"
|
83
82
|
#
|
84
83
|
# gcloud = Gcloud.new
|
@@ -103,10 +102,9 @@ module Gcloud
|
|
103
102
|
# to the regular expression <code>([a-z]([-a-z0-9]*[a-z0-9])?)?</code>.
|
104
103
|
#
|
105
104
|
# No more than 256 labels can be associated with a given resource.
|
106
|
-
# (
|
107
|
-
#
|
108
|
-
# === Example
|
105
|
+
# (`Hash`)
|
109
106
|
#
|
107
|
+
# @example
|
110
108
|
# require "gcloud"
|
111
109
|
#
|
112
110
|
# gcloud = Gcloud.new
|
@@ -121,8 +119,8 @@ module Gcloud
|
|
121
119
|
end
|
122
120
|
|
123
121
|
##
|
124
|
-
# Create an Updater object.
|
125
|
-
def self.from_project project
|
122
|
+
# @private Create an Updater object.
|
123
|
+
def self.from_project project
|
126
124
|
dupe_gapi = project.gapi.dup
|
127
125
|
dupe_gapi = dupe_gapi.to_hash if dupe_gapi.respond_to? :to_hash
|
128
126
|
if dupe_gapi["labels"].respond_to? :to_hash
|
data/lib/gcloud/search.rb
CHANGED
@@ -12,38 +12,34 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
|
15
16
|
require "gcloud"
|
16
17
|
require "gcloud/search/project"
|
17
18
|
|
18
|
-
#--
|
19
|
-
# Google Cloud Search
|
20
19
|
module Gcloud
|
21
20
|
##
|
22
|
-
# Creates a new
|
21
|
+
# Creates a new `Project` instance connected to the Search service.
|
23
22
|
# Each call creates a new connection.
|
24
23
|
#
|
25
|
-
#
|
24
|
+
# For more information on connecting to Google Cloud see the [Authentication
|
25
|
+
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
26
26
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# the connection can access. See {Using OAuth 2.0 to Access Google
|
36
|
-
# APIs}[https://developers.google.com/identity/protocols/OAuth2]. (+String+
|
37
|
-
# or +Array+)
|
27
|
+
# @param [String] project Identifier for a Search project. If not present, the
|
28
|
+
# default project for the credentials is used.
|
29
|
+
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If file
|
30
|
+
# path the file must be readable.
|
31
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
32
|
+
# set of resources and operations that the connection can access. See [Using
|
33
|
+
# OAuth 2.0 to Access Google
|
34
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
38
35
|
#
|
39
36
|
# The default scopes are:
|
40
37
|
#
|
41
|
-
# *
|
42
|
-
# *
|
38
|
+
# * `https://www.googleapis.com/auth/cloudsearch`
|
39
|
+
# * `https://www.googleapis.com/auth/userinfo.email`
|
43
40
|
#
|
44
|
-
#
|
41
|
+
# @return [Gcloud::Search::Project]
|
45
42
|
#
|
46
|
-
# Gcloud::Search::Project
|
47
43
|
def self.search project = nil, keyfile = nil, scope: nil
|
48
44
|
project ||= Gcloud::Search::Project.default_project
|
49
45
|
if keyfile.nil?
|
@@ -58,7 +54,7 @@ module Gcloud
|
|
58
54
|
# Disabled because there are links in the docs that are long.
|
59
55
|
|
60
56
|
##
|
61
|
-
#
|
57
|
+
# # Google Cloud Search
|
62
58
|
#
|
63
59
|
# Google Cloud Search allows an application to quickly perform full-text and
|
64
60
|
# geo-spatial searches without having to spin up instances and without the
|
@@ -74,220 +70,247 @@ module Gcloud
|
|
74
70
|
# backward-incompatible ways. It is not currently recommended for production
|
75
71
|
# use. It is not subject to any SLA or deprecation policy.
|
76
72
|
#
|
77
|
-
#
|
73
|
+
# ## Accessing the Service
|
78
74
|
#
|
79
75
|
# Currently, the Cloud Search API is available only to white-listed users.
|
80
76
|
# Contact your account manager or a member of the Google Cloud sales team if
|
81
77
|
# you are interested in access.
|
82
78
|
#
|
83
|
-
#
|
79
|
+
# ## Authentication
|
84
80
|
#
|
85
|
-
# Authentication is handled by Gcloud#search. You can provide the project and
|
81
|
+
# Authentication is handled by {Gcloud#search}. You can provide the project and
|
86
82
|
# credential information to connect to the Cloud Search service, or if you are
|
87
83
|
# running on Google Compute Engine this configuration is taken care of for
|
88
84
|
# you. You can read more about the options for connecting in the
|
89
|
-
#
|
85
|
+
# [Authentication
|
86
|
+
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
90
87
|
#
|
91
|
-
#
|
88
|
+
# ## Managing Indexes
|
92
89
|
#
|
93
90
|
# An Index is a searchable collection of documents that belongs to a Project.
|
94
91
|
#
|
95
92
|
# You can list the indexes in your current project:
|
96
93
|
#
|
97
|
-
#
|
94
|
+
# ```ruby
|
95
|
+
# require "gcloud"
|
98
96
|
#
|
99
|
-
#
|
100
|
-
#
|
97
|
+
# gcloud = Gcloud.new
|
98
|
+
# search = gcloud.search
|
101
99
|
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
100
|
+
# indexes = search.indexes # API call
|
101
|
+
# indexes.each do |index|
|
102
|
+
# puts index.index_id
|
103
|
+
# end
|
104
|
+
# ```
|
106
105
|
#
|
107
106
|
# And you can use the project to create new indexes:
|
108
107
|
#
|
109
|
-
#
|
108
|
+
# ```ruby
|
109
|
+
# require "gcloud"
|
110
110
|
#
|
111
|
-
#
|
112
|
-
#
|
111
|
+
# gcloud = Gcloud.new
|
112
|
+
# search = gcloud.search
|
113
113
|
#
|
114
|
-
#
|
114
|
+
# index = search.index "products", skip_lookup: true
|
115
|
+
# ```
|
115
116
|
#
|
116
117
|
# A new index is an unsaved value object. Indexes cannot be created,
|
117
118
|
# updated, or deleted directly in the service: They are derived from the
|
118
119
|
# documents which are created "within" them. A new index will exist in the
|
119
120
|
# service once you save a document that references it.
|
120
121
|
#
|
121
|
-
#
|
122
|
+
# ## Managing Documents
|
122
123
|
#
|
123
124
|
# Using an index, create a new, unsaved Document instance, providing
|
124
125
|
# your own unique document ID, as shown below, or omitting this argument to
|
125
126
|
# let the service assign the ID.
|
126
127
|
#
|
127
|
-
#
|
128
|
+
# ```ruby
|
129
|
+
# require "gcloud"
|
128
130
|
#
|
129
|
-
#
|
130
|
-
#
|
131
|
+
# gcloud = Gcloud.new
|
132
|
+
# search = gcloud.search
|
131
133
|
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
134
|
+
# index = search.index "products"
|
135
|
+
# document = index.document "product-sku-000001"
|
136
|
+
# index.find document # API call
|
137
|
+
# #=> nil
|
138
|
+
# document.rank #=> nil
|
139
|
+
# ```
|
137
140
|
#
|
138
|
-
# Add one or more fields to the document. (See
|
141
|
+
# Add one or more fields to the document. (See [Adding document fields](#module-Gcloud::Search-label-Adding`document`fields), below.)
|
139
142
|
#
|
140
|
-
#
|
143
|
+
# ```ruby
|
144
|
+
# document.add "price", 24.95
|
145
|
+
# ```
|
141
146
|
#
|
142
147
|
# When your document is complete, save it:
|
143
148
|
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
149
|
+
# ```ruby
|
150
|
+
# index.save document # API call
|
151
|
+
# document.rank # set by the server
|
152
|
+
# #=> 1443648166
|
153
|
+
# ```
|
147
154
|
#
|
148
155
|
# You can list the documents in an index:
|
149
156
|
#
|
150
|
-
#
|
157
|
+
# ```ruby
|
158
|
+
# require "gcloud"
|
151
159
|
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
160
|
+
# gcloud = Gcloud.new
|
161
|
+
# search = gcloud.search
|
162
|
+
# index = search.index "products"
|
155
163
|
#
|
156
|
-
#
|
157
|
-
#
|
164
|
+
# documents = index.documents # API call
|
165
|
+
# documents.map &:doc_id #=> ["product-sku-000001"]
|
166
|
+
# ```
|
158
167
|
#
|
159
168
|
# And you can delete documents:
|
160
169
|
#
|
161
|
-
#
|
170
|
+
# ```ruby
|
171
|
+
# require "gcloud"
|
162
172
|
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
173
|
+
# gcloud = Gcloud.new
|
174
|
+
# search = gcloud.search
|
175
|
+
# index = search.index "products"
|
166
176
|
#
|
167
|
-
#
|
177
|
+
# document = index.find "product-sku-000001"
|
168
178
|
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
179
|
+
# document.delete # API call
|
180
|
+
# index.find document # API call
|
181
|
+
# #=> nil
|
182
|
+
# ```
|
172
183
|
#
|
173
184
|
# To update a document after manipulating its fields or rank, just re-save it:
|
174
185
|
#
|
175
|
-
#
|
186
|
+
# ```ruby
|
187
|
+
# require "gcloud"
|
176
188
|
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
189
|
+
# gcloud = Gcloud.new
|
190
|
+
# search = gcloud.search
|
191
|
+
# index = search.index "products"
|
180
192
|
#
|
181
|
-
#
|
193
|
+
# document = index.find "product-sku-000001"
|
182
194
|
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
195
|
+
# document.rank = 12345
|
196
|
+
# document.add "price", 9.95 # replace existing number value
|
197
|
+
# index.save document # API call
|
198
|
+
# ```
|
186
199
|
#
|
187
|
-
#
|
200
|
+
# ## Adding document fields
|
188
201
|
#
|
189
202
|
# Fields belong to documents and are the data that actually gets searched.
|
190
203
|
# Each field has a FieldValues collection, which facilitates access to
|
191
204
|
# FieldValue objects. Each FieldValue object will be saved as one of the
|
192
|
-
#
|
205
|
+
# [Cloud Search types](https://cloud.google.com/search/documents_indexes#document_fields_field_names_and_multi-valued_fields).
|
193
206
|
# The type will be inferred from the value when possible, or you can
|
194
|
-
# explicitly specify it by passing a symbol with the
|
195
|
-
# Document#add.
|
207
|
+
# explicitly specify it by passing a symbol with the `type` option to
|
208
|
+
# {Gcloud::Search::Document#add}.
|
196
209
|
#
|
197
|
-
# - String (
|
198
|
-
# - Number (
|
199
|
-
# - Timestamp (
|
200
|
-
# - Geovalue (
|
210
|
+
# - String (`:atom`, `:html`, `:text`, or `:default`)
|
211
|
+
# - Number (`:number`)
|
212
|
+
# - Timestamp (`:datetime`)
|
213
|
+
# - Geovalue (`:geo`)
|
201
214
|
#
|
202
215
|
# String values can be tokenized using one of three different types of
|
203
|
-
# tokenization, which can be passed with the
|
216
|
+
# tokenization, which can be passed with the `type` option when the value is
|
204
217
|
# added:
|
205
218
|
#
|
206
|
-
# -
|
219
|
+
# - `:atom` means "don't tokenize this string", treat it as one
|
207
220
|
# thing to compare against
|
208
221
|
#
|
209
|
-
# -
|
210
|
-
# tags, and treating the rest of the content like
|
222
|
+
# - `:html` means "treat this string as HTML", not comparing against the
|
223
|
+
# tags, and treating the rest of the content like `:text`
|
211
224
|
#
|
212
|
-
# -
|
225
|
+
# - `:text` means "treat this string as normal text" and split words
|
213
226
|
# apart to be compared against
|
214
227
|
#
|
215
228
|
# Again, you can add more than one value to a field, and the values may be of
|
216
229
|
# different types.
|
217
230
|
#
|
218
|
-
#
|
231
|
+
# ```ruby
|
232
|
+
# require "gcloud"
|
219
233
|
#
|
220
|
-
#
|
221
|
-
#
|
234
|
+
# gcloud = Gcloud.new
|
235
|
+
# search = gcloud.search
|
222
236
|
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
237
|
+
# index = search.index "products"
|
238
|
+
# document = index.find "product-sku-000001"
|
239
|
+
# document.add "description", "The best T-shirt ever.", type: :text, lang: "en"
|
240
|
+
# document.add "description", "<p>The best T-shirt ever.</p>", type: :html, lang: "en"
|
241
|
+
# document["description"].size #=> 2
|
242
|
+
# ```
|
228
243
|
#
|
229
|
-
#
|
244
|
+
# ## Searching
|
230
245
|
#
|
231
246
|
# After populating an index with documents, you can request search results
|
232
247
|
# with a query:
|
233
248
|
#
|
234
|
-
#
|
249
|
+
# ```ruby
|
250
|
+
# require "gcloud"
|
235
251
|
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
#
|
252
|
+
# gcloud = Gcloud.new
|
253
|
+
# search = gcloud.search
|
254
|
+
# index = search.index "books"
|
239
255
|
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
256
|
+
# results = index.search "dark stormy"
|
257
|
+
# results.each do |result|
|
258
|
+
# puts result.doc_id
|
259
|
+
# end
|
260
|
+
# ```
|
244
261
|
#
|
245
262
|
# By default, Result objects are sorted by document rank. For more information
|
246
|
-
# see the
|
263
|
+
# see the [REST API documentation for Document.rank](https://cloud.google.com/search/reference/rest/v1/projects/indexes/documents#resource_representation.google.cloudsearch.v1.Document.rank).
|
247
264
|
#
|
248
|
-
# You can specify how to sort results with the
|
265
|
+
# You can specify how to sort results with the `order` option:
|
249
266
|
#
|
250
|
-
#
|
267
|
+
# ```ruby
|
268
|
+
# require "gcloud"
|
251
269
|
#
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
270
|
+
# gcloud = Gcloud.new
|
271
|
+
# search = gcloud.search
|
272
|
+
# index = search.index "books"
|
255
273
|
#
|
256
|
-
#
|
257
|
-
#
|
274
|
+
# results = index.search "dark stormy", order: "published, avg_review desc"
|
275
|
+
# documents = index.search query # API call
|
276
|
+
# ```
|
258
277
|
#
|
259
|
-
# You can add computed fields with the
|
260
|
-
# fields that are returned with the
|
261
|
-
# returned if you omit the
|
278
|
+
# You can add computed fields with the `expressions` option, and specify the
|
279
|
+
# fields that are returned with the `fields` option. No document data will be
|
280
|
+
# returned if you omit the `fields` option, only `doc_id` references to any
|
262
281
|
# matched documents.
|
263
282
|
#
|
264
|
-
#
|
283
|
+
# ```ruby
|
284
|
+
# require "gcloud"
|
265
285
|
#
|
266
|
-
#
|
267
|
-
#
|
268
|
-
#
|
286
|
+
# gcloud = Gcloud.new
|
287
|
+
# search = gcloud.search
|
288
|
+
# index = search.index "products"
|
269
289
|
#
|
270
|
-
#
|
271
|
-
#
|
272
|
-
#
|
290
|
+
# results = index.search "cotton T-shirt",
|
291
|
+
# expressions: { total_price: "(price + tax)" },
|
292
|
+
# fields: ["name", "total_price", "highlight"]
|
293
|
+
# ```
|
273
294
|
#
|
274
295
|
# Just as in documents, Result data is accessible via Fields methods:
|
275
296
|
#
|
276
|
-
#
|
277
|
-
#
|
278
|
-
#
|
279
|
-
#
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
297
|
+
# ```ruby
|
298
|
+
# require "gcloud"
|
299
|
+
#
|
300
|
+
# gcloud = Gcloud.new
|
301
|
+
# search = gcloud.search
|
302
|
+
# index = search.index "products"
|
303
|
+
# document = index.find "product-sku-000001"
|
304
|
+
# results = index.search "cotton T-shirt"
|
305
|
+
# values = results[0]["description"]
|
306
|
+
#
|
307
|
+
# values[0] #=> "100% organic cotton ruby gem T-shirt"
|
308
|
+
# values[0].type #=> :text
|
309
|
+
# values[0].lang #=> "en"
|
310
|
+
# values[1] #=> "<p>100% organic cotton ruby gem T-shirt</p>"
|
311
|
+
# values[1].type #=> :html
|
312
|
+
# values[1].lang #=> "en"
|
313
|
+
# ```
|
291
314
|
#
|
292
315
|
module Search
|
293
316
|
end
|