Retail V2 API - Class Google::Cloud::Retail::V2::CompletionService::Client (v1.2.0)

Reference documentation and code samples for the Retail V2 API class Google::Cloud::Retail::V2::CompletionService::Client.

Client for the CompletionService service.

Autocomplete service for retail.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the CompletionService Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all CompletionService clients
::Google::Cloud::Retail::V2::CompletionService::Client.configure do |config|
  config.timeout = 10.0
end

#complete_query

def complete_query(request, options = nil) -> ::Google::Cloud::Retail::V2::CompleteQueryResponse
def complete_query(catalog: nil, query: nil, visitor_id: nil, language_codes: nil, device_type: nil, dataset: nil, max_suggestions: nil, enable_attribute_suggestions: nil, entity: nil) -> ::Google::Cloud::Retail::V2::CompleteQueryResponse

Completes the specified prefix with keyword suggestions.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

Overloads
def complete_query(request, options = nil) -> ::Google::Cloud::Retail::V2::CompleteQueryResponse
Pass arguments to complete_query via a request object, either of type Google::Cloud::Retail::V2::CompleteQueryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::CompleteQueryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def complete_query(catalog: nil, query: nil, visitor_id: nil, language_codes: nil, device_type: nil, dataset: nil, max_suggestions: nil, enable_attribute_suggestions: nil, entity: nil) -> ::Google::Cloud::Retail::V2::CompleteQueryResponse
Pass arguments to complete_query via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • catalog (::String) — Required. Catalog for which the completion is performed.

    Full resource name of catalog, such as projects/*/locations/global/catalogs/default_catalog.

  • query (::String) — Required. The query used to generate suggestions.

    The maximum number of allowed characters is 255.

  • visitor_id (::String) — Required field. A unique identifier for tracking visitors. For example, this could be implemented with an HTTP cookie, which should be able to uniquely identify a visitor on a single device. This unique identifier should not change if the visitor logs in or out of the website.

    The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned.

  • language_codes (::Array<::String>) — Note that this field applies for user-data dataset only. For requests with cloud-retail dataset, setting this field has no effect.

    The language filters applied to the output suggestions. If set, it should contain the language of the query. If not set, suggestions are returned without considering language restrictions. This is the BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see Tags for Identifying Languages. The maximum number of language codes is 3.

  • device_type (::String) —

    The device type context for completion suggestions. We recommend that you leave this field empty.

    It can apply different suggestions on different device types, e.g. DESKTOP, MOBILE. If it is empty, the suggestions are across all device types.

    Supported formats:

    • UNKNOWN_DEVICE_TYPE

    • DESKTOP

    • MOBILE

    • A customized string starts with OTHER_, e.g. OTHER_IPHONE.

  • dataset (::String) —

    Determines which dataset to use for fetching completion. "user-data" will use the imported dataset through CompletionService.ImportCompletionData. "cloud-retail" will use the dataset generated by cloud retail based on user events. If leave empty, it will use the "user-data".

    Current supported values:

    • user-data

    • cloud-retail: This option requires enabling auto-learning function first. See guidelines.

  • max_suggestions (::Integer) — Completion max suggestions. If left unset or set to 0, then will fallback to the configured value CompletionConfig.max_suggestions.

    The maximum allowed max suggestions is 20. If it is set higher, it will be capped by 20.

  • enable_attribute_suggestions (::Boolean) — If true, attribute suggestions are enabled and provided in the response.

    This field is only available for the "cloud-retail" dataset.

  • entity (::String) — The entity for customers who run multiple entities, domains, sites, or regions, for example, Google US, Google Ads, Waymo, google.com, youtube.com, etc. If this is set, it must be an exact match with UserEvent.entity to get per-entity autocomplete results.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::CompletionService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::CompleteQueryRequest.new

# Call the complete_query method.
result = client.complete_query request

# The returned object is of type Google::Cloud::Retail::V2::CompleteQueryResponse.
p result

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the CompletionService Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#import_completion_data

def import_completion_data(request, options = nil) -> ::Gapic::Operation
def import_completion_data(parent: nil, input_config: nil, notification_pubsub_topic: nil) -> ::Gapic::Operation

Bulk import of processed completion dataset.

Request processing is asynchronous. Partial updating is not supported.

The operation is successfully finished only after the imported suggestions are indexed successfully and ready for serving. The process takes hours.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

Overloads
def import_completion_data(request, options = nil) -> ::Gapic::Operation
Pass arguments to import_completion_data via a request object, either of type ImportCompletionDataRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::ImportCompletionDataRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def import_completion_data(parent: nil, input_config: nil, notification_pubsub_topic: nil) -> ::Gapic::Operation
Pass arguments to import_completion_data via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The catalog which the suggestions dataset belongs to.

    Format: projects/1234/locations/global/catalogs/default_catalog.

  • input_config (::Google::Cloud::Retail::V2::CompletionDataInputConfig, ::Hash) — Required. The desired input location of the data.
  • notification_pubsub_topic (::String) — Pub/Sub topic for receiving notification. If this field is set, when the import is finished, a notification is sent to specified Pub/Sub topic. The message data is JSON string of a Operation. Format of the Pub/Sub topic is projects/{project}/topics/{topic}.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::CompletionService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::ImportCompletionDataRequest.new

# Call the import_completion_data method.
result = client.import_completion_data request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#initialize

def initialize() { |config| ... } -> Client

Create a new CompletionService client object.

Yields
  • (config) — Configure the CompletionService client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Retail::V2::CompletionService::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Retail::V2::CompletionService::Client.new do |config|
  config.timeout = 10.0
end

#location_client

def location_client() -> Google::Cloud::Location::Locations::Client

Get the associated client for mix-in of the Locations.

Returns
  • (Google::Cloud::Location::Locations::Client)

#logger

def logger() -> Logger

The logger used for request/response debug logging.

Returns
  • (Logger)

#operations_client

def operations_client() -> ::Google::Cloud::Retail::V2::CompletionService::Operations

Get the associated client for long-running operations.

#universe_domain

def universe_domain() -> String

The effective universe domain

Returns
  • (String)