From 5628077e982516a1715f2bd427d9d61c2dd743f7 Mon Sep 17 00:00:00 2001 From: dfirova <93149631+dfirova@users.noreply.github.com> Date: Wed, 21 Sep 2022 20:10:24 +0300 Subject: [PATCH] chore(samples): improved message if no result returned in search tutorials. (#537) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …als. Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-retail/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes # ☕️ If you write sample code, please follow the [samples format]( https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md). --- .../src/main/java/search/SearchSimpleQuery.java | 6 +++++- .../src/main/java/search/SearchWithBoostSpec.java | 6 +++++- .../src/main/java/search/SearchWithFacetSpec.java | 6 +++++- .../src/main/java/search/SearchWithFiltering.java | 6 +++++- .../src/main/java/search/SearchWithOrdering.java | 6 +++++- .../src/main/java/search/SearchWithPagination.java | 6 +++++- .../src/main/java/search/SearchWithQueryExpansionSpec.java | 6 +++++- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/retail/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java b/retail/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java index 545018e8aeb..e2bc4c3639c 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java @@ -60,7 +60,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponse.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponse); + } } } } diff --git a/retail/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java b/retail/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java index 8cead0d856e..caf5df7dba0 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java @@ -71,7 +71,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponse.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponse); + } } } } diff --git a/retail/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java b/retail/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java index 37029c6273f..9688a871c78 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java @@ -62,7 +62,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponse.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponse); + } } } } diff --git a/retail/interactive-tutorials/src/main/java/search/SearchWithFiltering.java b/retail/interactive-tutorials/src/main/java/search/SearchWithFiltering.java index 69b2653eda9..1c46b16454d 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchWithFiltering.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchWithFiltering.java @@ -63,7 +63,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponse.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponse); + } } } } diff --git a/retail/interactive-tutorials/src/main/java/search/SearchWithOrdering.java b/retail/interactive-tutorials/src/main/java/search/SearchWithOrdering.java index c2623b604f8..d3139a080e9 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchWithOrdering.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchWithOrdering.java @@ -62,7 +62,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponse.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponse); + } } } } diff --git a/retail/interactive-tutorials/src/main/java/search/SearchWithPagination.java b/retail/interactive-tutorials/src/main/java/search/SearchWithPagination.java index b288397b430..c3d80c1ac62 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchWithPagination.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchWithPagination.java @@ -65,7 +65,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponseFirstPage.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponseFirstPage); + } // PASTE CALL WITH NEXT PAGE TOKEN HERE: diff --git a/retail/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java b/retail/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java index c08552e978a..0576de17e2b 100644 --- a/retail/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java +++ b/retail/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java @@ -68,7 +68,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx // 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); + if (searchResponse.getTotalSize() == 0) { + System.out.println("The search operation returned no matching results."); + } else { + System.out.println("Search response: " + searchResponse); + } } } }