From b998aa204c6390e9653f6f59f5299a2e8d49f1d3 Mon Sep 17 00:00:00 2001 From: tetiana-karasova Date: Tue, 22 Mar 2022 01:34:29 +0100 Subject: [PATCH 1/9] Update README --- samples/interactive-tutorials/README.md | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/samples/interactive-tutorials/README.md b/samples/interactive-tutorials/README.md index 797fd27d..180377b2 100644 --- a/samples/interactive-tutorials/README.md +++ b/samples/interactive-tutorials/README.md @@ -53,6 +53,7 @@ If you don't have a Google Cloud project yet or you're not the owner of an exist [create a new project](https://console.cloud.google.com/projectcreate). After the project is created, set your PROJECT_ID to a ```project``` variable. + 1. Run the following command in Terminal: ```bash gcloud config set project @@ -99,16 +100,6 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th export GOOGLE_APPLICATION_CREDENTIALS=~/key.json ``` -### Set the GOOGLE_CLOUD_PROJECT environment variable - -You will run the code samples in your own Google Cloud project. To use the **project_id** in every request to the Retail API, you should first specify them as environment variables. - -1. Find the project ID in the Project Info card displayed on **Home/Dashboard**. - -1. Set the **project_id** with the following command: - ```bash - export GOOGLE_CLOUD_PROJECT= - ## Import Catalog Data This step is required if this is the first Retail API Tutorial you run. From 756a39ce0ea4dcc30d98c1cef494f5aa80e884aa Mon Sep 17 00:00:00 2001 From: t-karasova Date: Thu, 31 Mar 2022 17:01:41 +0200 Subject: [PATCH 2/9] the bash scripts are added --- samples/interactive-tutorials/README.md | 19 ++----- .../user_environment_setup.sh | 53 +++++++++++++++++++ .../user_import_data_to_catalog.sh | 36 +++++++++++++ 3 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 samples/interactive-tutorials/user_environment_setup.sh create mode 100644 samples/interactive-tutorials/user_import_data_to_catalog.sh diff --git a/samples/interactive-tutorials/README.md b/samples/interactive-tutorials/README.md index 180377b2..e4451533 100644 --- a/samples/interactive-tutorials/README.md +++ b/samples/interactive-tutorials/README.md @@ -1,6 +1,6 @@ -#Retail Search Interactive Tutorials +# Retail Search Interactive Tutorials -##Run tutorials in Cloud Shell +## Run tutorials in Cloud Shell To advance with the interactive tutorials, use Retail Search step-by-step manuals on the right side of the Cloud Shell IDE: ![Interactive tutorials](images/tutorial1.png) @@ -76,15 +76,6 @@ To access the Retail API, you must create a service account. To run a code sample from the Cloud Shell, you need to be authenticated using the service account credentials. -1. Login with your user credentials. - ```bash - gcloud auth login - ``` - -1. Type `Y` and press **Enter**. Click the link in a Terminal. A browser window should appear asking you to log in using your Gmail account. - -1. Provide the Google Auth Library with access to your credentials and paste the code from the browser to the Terminal. - 1. Upload your service account key JSON file and use it to activate the service account: ```bash @@ -116,9 +107,8 @@ In your own project, create a Cloud Storage bucket and put the JSON file there. The bucket name must be unique. For convenience, you can name it `_`. 1. To create the bucket and upload the JSON file, run the following command in the Terminal: - ```bash - pmvn compile exec:java -Dexec.mainClass=CreateGcsBucket + mvn compile exec:java -Dexec.mainClass="product.setup.ProductsCreateGcsBucket" ``` Now you can see the bucket is created in the [Cloud Storage](https://console.cloud.google.com/storage/browser), and the files are uploaded. @@ -132,9 +122,8 @@ The bucket name must be unique. For convenience, you can name it ` ```bash - pmvn compile exec:java -Dexec.mainClass=ImportProductsGcs + mvn compile exec:java -Dexec.mainClass="product.ImportProductsGcs" ``` ### Running code samples diff --git a/samples/interactive-tutorials/user_environment_setup.sh b/samples/interactive-tutorials/user_environment_setup.sh new file mode 100644 index 00000000..7cee8cd3 --- /dev/null +++ b/samples/interactive-tutorials/user_environment_setup.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Copyright 2022 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set the Google Cloud project Id +project_id=$1 +echo Project ID: $project_id +gcloud config set project project_id + +timestamp=$(date +%s) + +service_account_id="service-acc-"$timestamp +echo Service Account: $service_account_id + +# create service account (your project_id+timestamp) +gcloud iam service-accounts create $service_account_id + +# assign needed roles to your new service account +for role in {retail.admin,editor,bigquery.admin} + do + gcloud projects add-iam-policy-binding $project_id --member="serviceAccount:"$service_account_id"@"$project_id".iam.gserviceaccount.com" --role="roles/${role}" +done + +echo Wait 70 seconds to be sure the appropriate roles have been assigned to your service account +sleep 70 + +# upload your service account key file +service_acc_email=$service_account_id"@"$project_id".iam.gserviceaccount.com" +gcloud iam service-accounts keys create ~/key.json --iam-account $service_acc_email + +# activate the service account using the key +gcloud auth activate-service-account --key-file ~/key.json + +# install needed Google client libraries +cd ~/cloudshell_open/java-retail/samples/interactive-tutorials +mvn clean install -DskipTests + +echo ======================================== +echo "The Google Cloud setup is completed." +echo "Please proceed with the Tutorial steps" +echo ======================================== diff --git a/samples/interactive-tutorials/user_import_data_to_catalog.sh b/samples/interactive-tutorials/user_import_data_to_catalog.sh new file mode 100644 index 00000000..ac8a1a08 --- /dev/null +++ b/samples/interactive-tutorials/user_import_data_to_catalog.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Copyright 2022 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set the key as GOOGLE_APPLICATION_CREDENTIALS +export GOOGLE_APPLICATION_CREDENTIALS=~/key.json + +# Change the working directory +cd ~/cloudshell_open/java-retail/samples/interactive-tutorials/ + +# Create a GCS bucket and upload the product data to the bucket +output=$(mvn compile exec:java -Dexec.mainClass="product.setup.ProductsCreateGcsBucket") + +# Get the bucket name and store it in the env variable BUCKET_NAME +temp="${output#*gcs bucket }" +bucket_name="${temp% was created*}" +export BUCKET_NAME=$bucket_name + +# Import products to the Retail catalog +mvn compile exec:java -Dexec.mainClass="product.ImportProductsGcs" + +echo ===================================== +echo "Your Retail catalog is ready to use!" +echo ===================================== From 8bd8e92d2d2f9bb838f9d72e17a1ff86fcbea0d0 Mon Sep 17 00:00:00 2001 From: t-karasova <91195610+t-karasova@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:44:09 +0200 Subject: [PATCH 3/9] Update README.md --- samples/interactive-tutorials/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/interactive-tutorials/README.md b/samples/interactive-tutorials/README.md index e4451533..383b03e3 100644 --- a/samples/interactive-tutorials/README.md +++ b/samples/interactive-tutorials/README.md @@ -55,6 +55,7 @@ If you don't have a Google Cloud project yet or you're not the owner of an exist After the project is created, set your PROJECT_ID to a ```project``` variable. 1. Run the following command in Terminal: + ```bash gcloud config set project ``` @@ -122,6 +123,7 @@ The bucket name must be unique. For convenience, you can name it ` Date: Fri, 1 Apr 2022 15:52:38 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69288030..e1c2389e 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-retail:2.0.16' +implementation 'com.google.cloud:google-cloud-retail:2.0.17' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-retail" % "2.0.16" +libraryDependencies += "com.google.cloud" % "google-cloud-retail" % "2.0.17" ``` ## Authentication From 5f976e4f30276488ca01997b4ba6be51afe1eacc Mon Sep 17 00:00:00 2001 From: t-karasova <91195610+t-karasova@users.noreply.github.com> Date: Fri, 1 Apr 2022 20:31:08 +0200 Subject: [PATCH 5/9] Update user_environment_setup.sh --- .../user_environment_setup.sh | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/samples/interactive-tutorials/user_environment_setup.sh b/samples/interactive-tutorials/user_environment_setup.sh index 7cee8cd3..46915b6f 100644 --- a/samples/interactive-tutorials/user_environment_setup.sh +++ b/samples/interactive-tutorials/user_environment_setup.sh @@ -14,40 +14,40 @@ # See the License for the specific language governing permissions and # limitations under the License. -# set the Google Cloud project Id +# set the Google Cloud Project ID project_id=$1 -echo Project ID: $project_id -gcloud config set project project_id +echo "Project ID: $project_id" +gcloud config set project "$project_id" timestamp=$(date +%s) -service_account_id="service-acc-"$timestamp -echo Service Account: $service_account_id +service_account_id="service-acc-$timestamp" +echo "Service Account: $service_account_id" -# create service account (your project_id+timestamp) -gcloud iam service-accounts create $service_account_id +# create service account (your service-acc-$timestamp) +gcloud iam service-accounts create "$service_account_id" -# assign needed roles to your new service account +# assign necessary roles to your new service account for role in {retail.admin,editor,bigquery.admin} do - gcloud projects add-iam-policy-binding $project_id --member="serviceAccount:"$service_account_id"@"$project_id".iam.gserviceaccount.com" --role="roles/${role}" + gcloud projects add-iam-policy-binding "$project_id" --member="serviceAccount:$service_account_id@$project_id.iam.gserviceaccount.com" --role=roles/"${role}" done -echo Wait 70 seconds to be sure the appropriate roles have been assigned to your service account -sleep 70 +echo "Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account" +sleep 60 # upload your service account key file -service_acc_email=$service_account_id"@"$project_id".iam.gserviceaccount.com" -gcloud iam service-accounts keys create ~/key.json --iam-account $service_acc_email +service_acc_email="$service_account_id@$project_id.iam.gserviceaccount.com" +gcloud iam service-accounts keys create ~/key.json --iam-account "$service_acc_email" # activate the service account using the key gcloud auth activate-service-account --key-file ~/key.json # install needed Google client libraries -cd ~/cloudshell_open/java-retail/samples/interactive-tutorials +cd ~/cloudshell_open/java-retail/samples/interactive-tutorials || exit mvn clean install -DskipTests -echo ======================================== +echo "========================================" echo "The Google Cloud setup is completed." echo "Please proceed with the Tutorial steps" -echo ======================================== +echo "========================================" From 475ef6fbddb9610a58a42a739dfc228d64d66e09 Mon Sep 17 00:00:00 2001 From: t-karasova <91195610+t-karasova@users.noreply.github.com> Date: Fri, 1 Apr 2022 20:33:58 +0200 Subject: [PATCH 6/9] Update user_import_data_to_catalog.sh --- .../interactive-tutorials/user_import_data_to_catalog.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/interactive-tutorials/user_import_data_to_catalog.sh b/samples/interactive-tutorials/user_import_data_to_catalog.sh index ac8a1a08..05c2747d 100644 --- a/samples/interactive-tutorials/user_import_data_to_catalog.sh +++ b/samples/interactive-tutorials/user_import_data_to_catalog.sh @@ -18,9 +18,9 @@ export GOOGLE_APPLICATION_CREDENTIALS=~/key.json # Change the working directory -cd ~/cloudshell_open/java-retail/samples/interactive-tutorials/ +cd ~/cloudshell_open/java-retail/samples/interactive-tutorials/ || exit -# Create a GCS bucket and upload the product data to the bucket +# Run the sample for creating the GCS bucket and extract the output of that execution output=$(mvn compile exec:java -Dexec.mainClass="product.setup.ProductsCreateGcsBucket") # Get the bucket name and store it in the env variable BUCKET_NAME @@ -31,6 +31,6 @@ export BUCKET_NAME=$bucket_name # Import products to the Retail catalog mvn compile exec:java -Dexec.mainClass="product.ImportProductsGcs" -echo ===================================== +echo "=====================================" echo "Your Retail catalog is ready to use!" -echo ===================================== +echo "=====================================" From 1df9f7a44d2d68158637457f199e00740876b63f Mon Sep 17 00:00:00 2001 From: t-karasova <91195610+t-karasova@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:38:24 +0200 Subject: [PATCH 7/9] Update README.md --- samples/interactive-tutorials/README.md | 134 +++++++++++++++++------- 1 file changed, 97 insertions(+), 37 deletions(-) diff --git a/samples/interactive-tutorials/README.md b/samples/interactive-tutorials/README.md index 383b03e3..c2957c23 100644 --- a/samples/interactive-tutorials/README.md +++ b/samples/interactive-tutorials/README.md @@ -36,48 +36,61 @@ The Retail API provides you with the following possibilities to: You can find the information about the Retail services in the [documentation](https://cloud.google.com/retail/docs) - If you would like to have a closer look at the Retail API features and try them yourself, -the best option is to use the [Interactive Tutorials](https://cloud.google.com/retail/docs/overview). The tutorials will be launched in the CloudShell environment, and you will be able to request the Retail services and check the response with minimum time and effort. +the best option is to use the [Interactive Tutorials](https://cloud.google.com/retail/docs/overview). In the documentation chapters find the "Guide me" button, the tutorials will be launched in the CloudShell environment, and you will be able to request the Retail services and check the response with minimum time and effort. -The code samples in the directory **python-retail/samples/interactive-tutorials** are explicitly created for use with the Retail Interactive Tutorials. +The code samples in the directory **java-retail/samples/interactive-tutorials** are explicitly created for use with the Retail Interactive Tutorials. If, for some reason, you have decided to proceed with these code samples without the tutorial, please go through the following steps and set up the required preconditions. -### Select your project and enable the Retail API +## Prepare your work environment -Google Cloud organizes resources into projects. This lets you -collect all the related resources for a single application in one place. +To prepare the work environment you should perform the following steps: +- Create a service account. +- Create a service account key and set it to authorize your calls to the Retail API. +- Install Google Cloud Retail library. -If you don't have a Google Cloud project yet or you're not the owner of an existing one, you can -[create a new project](https://console.cloud.google.com/projectcreate). +### There are two ways to set up your work environment: -After the project is created, set your PROJECT_ID to a ```project``` variable. - -1. Run the following command in Terminal: +- If you want to **speed up the process** of setting up the working environment, run the script java-retail/samples/interactive-tutorials/samples/interactive-tutorials/src/main/java/user_environment_setup.sh and skip the next **set up the work environment step-by-step** tutorial step: ```bash - gcloud config set project + bash java-retail/samples/interactive-tutorials/user_environment_setup.sh ``` -1. To check that the Retail API is enabled for your Project, go to the [Admin Console](https://console.cloud.google.com/ai/retail/). +- If you want to perform the environment set up step by step along with getting the explanation you should proceed with the next tutorial step. + +## Set up the work environment step-by-step ### Create service account -To access the Retail API, you must create a service account. +To access the Retail API, you must create a service account. Check that you are an owner of your Google Cloud project on the [IAM page](https://console.cloud.google.com/iam-admin/iam). + +1. To create a service account, perform the following command: -1. To create a service account, follow this [instruction](https://cloud.google.com/retail/docs/setting-up#service-account) + ```bash + gcloud iam service-accounts create + ``` -1. Find your service account on the [IAM page](https://console.cloud.google.com/iam-admin/iam), - click `Edit` icon, add the 'Storage Admin' and 'BigQuery Admin' roles. It may take some time for changes to apply. +1. Assign the needed roles to your service account: -1. Copy the service account email in the Principal field. + ```bash + for role in {retail.admin,editor,bigquery.admin} + do gcloud projects add-iam-policy-binding --member="serviceAccount:@.iam.gserviceaccount.com" --role="roles/${role}" + done + ``` + +1. Use the following command to show the service account email: + + ```bash + gcloud iam service-accounts list|grep + ``` -### Set up authentication + Copy the service account email. -To run a code sample from the Cloud Shell, you need to be authenticated using the service account credentials. -1. Upload your service account key JSON file and use it to activate the service account: +1. Upload your service account key JSON file and use it to activate the service + account: ```bash gcloud iam service-accounts keys create ~/key.json --iam-account @@ -87,34 +100,79 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th gcloud auth activate-service-account --key-file ~/key.json ``` -1. To request the Retail API, set your service account key JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable : +1. Set the key as the GOOGLE_APPLICATION_CREDENTIALS environment variable to + use it for sending requests to the Retail API. + ```bash export GOOGLE_APPLICATION_CREDENTIALS=~/key.json ``` -## Import Catalog Data +### Google Cloud Retail libraries -This step is required if this is the first Retail API Tutorial you run. -Otherwise, you can skip it. +Learn more about the [Java Google Cloud Retail library](https://googleapis.dev/java/google-cloud-retail/latest/index.html). -### Upload catalog data to Cloud Storage +## Congrats! You have configured your work environment + +1. Check that you are in the directory with code samples. + + The code samples for each of the Retail services are stored in different directories. + + Go to the code samples directory, your starting point to run more commands. + + ```bash + cd java-retail/samples/interactive-tutorials/ + ``` + +## Import catalog data + +This step is required if this is the first Retail API tutorial that you run. +Otherwise, you can skip it. + +There is a java-retail/samples/interactive-tutorials/src/main/resources/products.json file with valid products prepared in the `resources` directory. -There is a JSON file with valid products prepared in the `product` directory: -`product/resources/products.json`. +The other file, java-retail/samples/interactive-tutorials/src/main/resources/products_some_invalid.json, contains both valid and invalid products. You will use it to check the error handling. -Another file, `product/resources/products_some_invalid.json`, contains both valid and invalid products, and you will use it to check the error handling. +- If you want to **speed up the process**, run the following script in the Terminal directory to import all products to catalog and skip the next **Prepare the catalog data step-by-step** tutorial step: -In your own project, create a Cloud Storage bucket and put the JSON file there. + ```bash + bash java-retail/samples/interactive-tutorials/user_import_data_to_catalog.sh + ``` + +- If you want to upload products to the catalog step by step along with getting the explanation, you should proceed with the next tutorial step. + +## Prepare the catalog data step-by-step + +### Upload catalog data to Cloud Storage + +In your own project you need to create a Cloud Storage bucket and put the JSON file there. The bucket name must be unique. For convenience, you can name it `_`. -1. To create the bucket and upload the JSON file, run the following command in the Terminal: +1. The code samples for each of the Retail services are stored in different directories. + + Go to the code samples directory, your starting point to run more commands. + + ```bash + cd java-retail/samples/interactive-tutorials + ``` + +1. To create the bucket and upload the JSON file, open java-retail/samples/interactive-tutorials/src/main/java/product/setup/ProductsCreateGcsBucket.java file + +1. Go to the **product** directory and run the following command in the Terminal: + ```bash - mvn compile exec:java -Dexec.mainClass="product.setup.ProductsCreateGcsBucket" + mvn compile exec:java + -Dexec.mainClass=product.setup.ProductsCreateGcsBucket ``` Now you can see the bucket is created in the [Cloud Storage](https://console.cloud.google.com/storage/browser), and the files are uploaded. -1. The name of the created Retail Search bucket is printed in the Terminal. Copy the name and set it as the environment variable `BUCKET_NAME`: +1. The name of the created Cloud Storage bucket is shown in the Terminal. + + ``` + The gcs bucket _ was created + ``` + + Copy the name and set it as the environment variable `BUCKET_NAME`: ```bash export BUCKET_NAME= @@ -122,11 +180,13 @@ The bucket name must be unique. For convenience, you can name it ` Date: Mon, 25 Apr 2022 12:55:13 +0300 Subject: [PATCH 8/9] Refactoring search package. --- .../src/main/java/search/SearchSimpleQuery.java | 12 ++++++------ .../src/main/java/search/SearchWithBoostSpec.java | 12 ++++++------ .../src/main/java/search/SearchWithFacetSpec.java | 12 ++++++------ .../src/main/java/search/SearchWithFiltering.java | 12 ++++++------ .../src/main/java/search/SearchWithOrdering.java | 12 ++++++------ .../src/main/java/search/SearchWithPagination.java | 12 ++++++------ .../java/search/SearchWithQueryExpansionSpec.java | 12 ++++++------ .../src/test/java/search/SearchSimpleQueryTest.java | 7 +++++-- .../test/java/search/SearchWithBoostSpecTest.java | 7 +++++-- .../test/java/search/SearchWithFacetSpecTest.java | 7 +++++-- .../test/java/search/SearchWithFilteringTest.java | 7 +++++-- .../src/test/java/search/SearchWithOrderingTest.java | 7 +++++-- .../test/java/search/SearchWithPaginationTest.java | 7 +++++-- .../search/SearchWithQueryExpansionSpecTest.java | 7 +++++-- 14 files changed, 77 insertions(+), 56 deletions(-) diff --git a/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java b/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java index 23389950..935eb493 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java @@ -33,17 +33,15 @@ public class SearchSimpleQuery { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT QUERY PHRASES HERE: String queryPhrase = "Hoodie"; String visitorId = UUID.randomUUID().toString(); @@ -58,11 +56,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java b/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java index 784dbb5b..13777406 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java @@ -35,17 +35,15 @@ public class SearchWithBoostSpec { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT CONDITIONS HERE: String searchQuery = "Tee"; String condition = "(colorFamilies: ANY(\"Blue\"))"; @@ -69,11 +67,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java b/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java index 93000fde..d7131586 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java @@ -30,17 +30,15 @@ public class SearchWithFacetSpec { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT CONDITIONS HERE: String searchQuery = "Tee"; String facetKeyParam = "colorFamilies"; @@ -60,11 +58,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java b/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java index 27e2656b..44354872 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithFiltering.java @@ -33,17 +33,15 @@ public class SearchWithFiltering { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT FILTER EXPRESSIONS HERE: String filter = "(colorFamilies: ANY(\"Black\"))"; String queryPhrase = "Tee"; @@ -61,11 +59,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java b/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java index c71346cb..e3ca6270 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithOrdering.java @@ -33,17 +33,15 @@ public class SearchWithOrdering { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT ORDER BY EXPRESSION HERE: String order = "price desc"; String queryPhrase = "Hoodie"; @@ -60,11 +58,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java b/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java index f93c6f6d..0dae5016 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithPagination.java @@ -34,17 +34,15 @@ public class SearchWithPagination { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT PAGINATION PARAMETERS HERE: int pageSize = 6; String queryPhrase = "Hoodie"; @@ -63,6 +61,10 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponseFirstPage = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponseFirstPage); @@ -70,8 +72,6 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName // PASTE CALL WITH NEXT PAGE TOKEN HERE: // PASTE CALL WITH OFFSET HERE: - - return searchResponseFirstPage; } } } diff --git a/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java b/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java index d45ceda7..e98b5516 100644 --- a/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java +++ b/samples/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java @@ -36,17 +36,15 @@ public class SearchWithQueryExpansionSpec { public static void main(String[] args) throws IOException { - // TODO(developer): Replace these variables before running the sample. String projectId = ServiceOptions.getDefaultProjectId(); String defaultCatalogName = String.format("projects/%s/locations/global/catalogs/default_catalog", projectId); String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search"; - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } - public static SearchResponse getSearchResponse(String defaultSearchPlacementName) - throws IOException { + public static void searchResponse(String defaultSearchPlacementName) throws IOException { // TRY DIFFERENT QUERY EXPANSION CONDITION HERE: Condition condition = Condition.AUTO; int pageSize = 10; @@ -66,11 +64,13 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName .build(); System.out.println("Search request: " + searchRequest); + // Initialize client that will be used to send requests. This client only + // needs to be created once, and can be reused for multiple requests. After + // completing all of your requests, call the "close" method on the client to + // safely clean up any remaining background resources. try (SearchServiceClient client = SearchServiceClient.create()) { SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse(); System.out.println("Search response: " + searchResponse); - - return searchResponse; } } } diff --git a/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java b/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java index 7e9176b3..a5e8f118 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchSimpleQueryTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchSimpleQuery.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchSimpleQueryTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java index f291dbf3..aa93dd83 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithBoostSpecTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchWithBoostSpec.getSearchResponse; +import static search.SearchWithBoostSpec.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithBoostSpecTest { private ByteArrayOutputStream bout; private PrintStream originalPrintStream; @@ -43,7 +46,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java index 1f17de86..9b7a8c4d 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithFacetSpecTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchWithFacetSpec.getSearchResponse; +import static search.SearchWithFacetSpec.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithFacetSpecTest { private ByteArrayOutputStream bout; private PrintStream originalPrintStream; @@ -43,7 +46,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java index 2a5b16d3..25550258 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithFilteringTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithFiltering.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithFilteringTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java index b9051771..7a597745 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithOrderingTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithOrdering.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithOrderingTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java index a40a350d..1c9de653 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithPaginationTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithPagination.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithPaginationTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test diff --git a/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java b/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java index eca657c7..492ca775 100644 --- a/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java +++ b/samples/interactive-tutorials/src/test/java/search/SearchWithQueryExpansionSpecTest.java @@ -17,7 +17,7 @@ package search; import static com.google.common.truth.Truth.assertThat; -import static search.SearchSimpleQuery.getSearchResponse; +import static search.SearchWithQueryExpansionSpec.searchResponse; import com.google.cloud.ServiceOptions; import java.io.ByteArrayOutputStream; @@ -27,7 +27,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class SearchWithQueryExpansionSpecTest { private ByteArrayOutputStream bout; @@ -44,7 +47,7 @@ public void setUp() throws IOException, InterruptedException, ExecutionException originalPrintStream = System.out; System.setOut(out); - getSearchResponse(defaultSearchPlacementName); + searchResponse(defaultSearchPlacementName); } @Test From fa271c8577aff9b76121872f78ff8d37a3a2e985 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 11 Jul 2022 21:13:24 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f5b045cc..ddd1517c 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-retail:2.0.19' +implementation 'com.google.cloud:google-cloud-retail:2.3.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-retail" % "2.0.19" +libraryDependencies += "com.google.cloud" % "google-cloud-retail" % "2.3.0" ``` ## Authentication