# Retail V2 API - Class Google::Cloud::Retail::V2::CompletionService::Rest::Client (v2.9.0)

2.9.0 (latest) 2.8.1 2.7.0 2.6.1 2.5.0 2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.3.0 1.2.0 1.1.0 1.0.1 0.21.0 0.20.0 0.19.0 0.18.2 0.17.0 0.16.1 0.15.0 0.14.0 0.13.0 0.12.0 0.11.0 0.10.0 0.9.0 0.8.0 0.7.0 0.6.4 Reference documentation and code samples for the Retail V2 API class Google::Cloud::Retail::V2::CompletionService::Rest::Client.

REST client for the CompletionService service.


Autocomplete service for retail.

<br />

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

## Inherits

- Object

## Includes

- [Google::Cloud::Retail::V2::CompletionService::Paths](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Paths)

## Methods

### .configure

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

Configure the CompletionService Client class.


<br />

See [Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration "Google::Cloud::Retail::V2::CompletionService::Rest::Client::Configuration (class)")
for a description of the configuration fields.
**Yields**

- (config) --- Configure the Client client.
**Yield Parameter**

- **config** ([Client::Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration))
**Returns**

- ([Client::Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration))
**Example**

```ruby
# Modify the configuration for all CompletionService clients
::Google::Cloud::Retail::V2::CompletionService::Rest::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.


<br />

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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompleteQueryRequest "Google::Cloud::Retail::V2::CompleteQueryRequest (class)") or an equivalent Hash. **Parameters**

- **request** ([::Google::Cloud::Retail::V2::CompleteQueryRequest](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/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) --- Recommended 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](https://tools.ietf.org/html/bcp47). 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 dataset imported through
  [CompletionService.ImportCompletionData](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client#Google__Cloud__Retail__V2__CompletionService__Rest__Client_import_completion_data_instance_ "Google::Cloud::Retail::V2::CompletionService::Rest::Client#import_completion_data (method)").
  `cloud-retail` will use the dataset generated by Cloud Retail based on user
  events. If left empty, completions will be fetched from the `user-data`
  dataset.

  Current supported values:
  - user-data

  - cloud-retail:
    This option requires enabling auto-learning function first. See
    [guidelines](https://cloud.google.com/retail/docs/completion-overview#generated-completion-dataset).

- **max_suggestions** (::Integer) --- Completion max suggestions. If left unset or set to 0, then will fallback to the configured value [CompletionConfig.max_suggestions](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionConfig#Google__Cloud__Retail__V2__CompletionConfig_max_suggestions_instance_ "Google::Cloud::Retail::V2::CompletionConfig#max_suggestions (method)").


  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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-UserEvent#Google__Cloud__Retail__V2__UserEvent_entity_instance_ "Google::Cloud::Retail::V2::UserEvent#entity (method)") to get per-entity autocomplete results. This field will be applied to `completion_results` only. It has no effect on the `attribute_results`. Also, this entity should be limited to 256 characters, if too long, it will be truncated to 256 characters in both generation and serving time, and may lead to mis-match. To ensure it works, please set the entity with string within 256 characters.
**Yields**

- (result, operation) --- Access the result along with the TransportOperation object
**Yield Parameters**

- **result** ([::Google::Cloud::Retail::V2::CompleteQueryResponse](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompleteQueryResponse))
- **operation** (::Gapic::Rest::TransportOperation)
**Returns**

- ([::Google::Cloud::Retail::V2::CompleteQueryResponse](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompleteQueryResponse))
**Raises**

- (::Google::Cloud::Error) --- if the REST call is aborted.
**Example**

Basic example

```ruby
require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::CompletionService::Rest::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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client#Google__Cloud__Retail__V2__CompletionService__Rest__Client_configure_class_ "Google::Cloud::Retail::V2::CompletionService::Rest::Client.configure (method)").

<br />

See [Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration "Google::Cloud::Retail::V2::CompletionService::Rest::Client::Configuration (class)")
for a description of the configuration fields.
**Yields**

- (config) --- Configure the Client client.
**Yield Parameter**

- **config** ([Client::Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration))
**Returns**

- ([Client::Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration))

### #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.

<br />

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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-ImportCompletionDataRequest "Google::Cloud::Retail::V2::ImportCompletionDataRequest (class)") or an equivalent Hash. **Parameters**

- **request** ([::Google::Cloud::Retail::V2::ImportCompletionDataRequest](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Longrunning-Operation "Google::Longrunning::Operation (class)"). Format of the Pub/Sub topic is `projects/{project}/topics/{topic}`.
**Yields**

- (result, operation) --- Access the result along with the TransportOperation object
**Yield Parameters**

- **result** (::Gapic::Operation)
- **operation** (::Gapic::Rest::TransportOperation)
**Returns**

- (::Gapic::Operation)
**Raises**

- (::Google::Cloud::Error) --- if the REST call is aborted.
**Example**

Basic example

```ruby
require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::CompletionService::Rest::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 REST client object.
**Yields**

- (config) --- Configure the CompletionService client.
**Yield Parameter**

- **config** ([Client::Configuration](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client-Configuration))
**Returns**

- ([Client](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Client)) --- a new instance of Client
**Example**

```ruby
# Create a client using the default configuration
client = ::Google::Cloud::Retail::V2::CompletionService::Rest::Client.new

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

### #location_client

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

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

- (Google::Cloud::Location::Locations::Rest::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::Rest::Operations

Get the associated client for long-running operations.
**Returns**

- ([::Google::Cloud::Retail::V2::CompletionService::Rest::Operations](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-retail-v2/latest/Google-Cloud-Retail-V2-CompletionService-Rest-Operations))

### #universe_domain

    def universe_domain() -> String

The effective universe domain
**Returns**

- (String)