Skip to content

Commit 5628077

Browse files
authored
chore(samples): improved message if no result returned in search tutorials. (#537)
…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 #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 881695e commit 5628077

File tree

7 files changed

+35
-7
lines changed

7 files changed

+35
-7
lines changed

retail/interactive-tutorials/src/main/java/search/SearchSimpleQuery.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
6060
// safely clean up any remaining background resources.
6161
try (SearchServiceClient client = SearchServiceClient.create()) {
6262
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
63-
System.out.println("Search response: " + searchResponse);
63+
if (searchResponse.getTotalSize() == 0) {
64+
System.out.println("The search operation returned no matching results.");
65+
} else {
66+
System.out.println("Search response: " + searchResponse);
67+
}
6468
}
6569
}
6670
}

retail/interactive-tutorials/src/main/java/search/SearchWithBoostSpec.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
7171
// safely clean up any remaining background resources.
7272
try (SearchServiceClient client = SearchServiceClient.create()) {
7373
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
74-
System.out.println("Search response: " + searchResponse);
74+
if (searchResponse.getTotalSize() == 0) {
75+
System.out.println("The search operation returned no matching results.");
76+
} else {
77+
System.out.println("Search response: " + searchResponse);
78+
}
7579
}
7680
}
7781
}

retail/interactive-tutorials/src/main/java/search/SearchWithFacetSpec.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
6262
// safely clean up any remaining background resources.
6363
try (SearchServiceClient client = SearchServiceClient.create()) {
6464
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
65-
System.out.println("Search response: " + searchResponse);
65+
if (searchResponse.getTotalSize() == 0) {
66+
System.out.println("The search operation returned no matching results.");
67+
} else {
68+
System.out.println("Search response: " + searchResponse);
69+
}
6670
}
6771
}
6872
}

retail/interactive-tutorials/src/main/java/search/SearchWithFiltering.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
6363
// safely clean up any remaining background resources.
6464
try (SearchServiceClient client = SearchServiceClient.create()) {
6565
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
66-
System.out.println("Search response: " + searchResponse);
66+
if (searchResponse.getTotalSize() == 0) {
67+
System.out.println("The search operation returned no matching results.");
68+
} else {
69+
System.out.println("Search response: " + searchResponse);
70+
}
6771
}
6872
}
6973
}

retail/interactive-tutorials/src/main/java/search/SearchWithOrdering.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
6262
// safely clean up any remaining background resources.
6363
try (SearchServiceClient client = SearchServiceClient.create()) {
6464
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
65-
System.out.println("Search response: " + searchResponse);
65+
if (searchResponse.getTotalSize() == 0) {
66+
System.out.println("The search operation returned no matching results.");
67+
} else {
68+
System.out.println("Search response: " + searchResponse);
69+
}
6670
}
6771
}
6872
}

retail/interactive-tutorials/src/main/java/search/SearchWithPagination.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
6565
// safely clean up any remaining background resources.
6666
try (SearchServiceClient client = SearchServiceClient.create()) {
6767
SearchResponse searchResponseFirstPage = client.search(searchRequest).getPage().getResponse();
68-
System.out.println("Search response: " + searchResponseFirstPage);
68+
if (searchResponseFirstPage.getTotalSize() == 0) {
69+
System.out.println("The search operation returned no matching results.");
70+
} else {
71+
System.out.println("Search response: " + searchResponseFirstPage);
72+
}
6973

7074
// PASTE CALL WITH NEXT PAGE TOKEN HERE:
7175

retail/interactive-tutorials/src/main/java/search/SearchWithQueryExpansionSpec.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ public static void searchResponse(String defaultSearchPlacementName) throws IOEx
6868
// safely clean up any remaining background resources.
6969
try (SearchServiceClient client = SearchServiceClient.create()) {
7070
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
71-
System.out.println("Search response: " + searchResponse);
71+
if (searchResponse.getTotalSize() == 0) {
72+
System.out.println("The search operation returned no matching results.");
73+
} else {
74+
System.out.println("Search response: " + searchResponse);
75+
}
7276
}
7377
}
7478
}

0 commit comments

Comments
 (0)