Skip to content

Commit

Permalink
chore(samples): improved message if no result returned in search tuto…
Browse files Browse the repository at this point in the history
…rials. (#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).
  • Loading branch information
dfirova authored Sep 21, 2022
1 parent 881695e commit 5628077
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 5628077

Please sign in to comment.