34
34
public class SearchWithPagination {
35
35
36
36
public static void main (String [] args ) throws IOException {
37
- // TODO(developer): Replace these variables before running the sample.
38
37
String projectId = ServiceOptions .getDefaultProjectId ();
39
38
String defaultCatalogName =
40
39
String .format ("projects/%s/locations/global/catalogs/default_catalog" , projectId );
41
40
String defaultSearchPlacementName = defaultCatalogName + "/placements/default_search" ;
42
41
43
- getSearchResponse (defaultSearchPlacementName );
42
+ searchResponse (defaultSearchPlacementName );
44
43
}
45
44
46
- public static SearchResponse getSearchResponse (String defaultSearchPlacementName )
47
- throws IOException {
45
+ public static void searchResponse (String defaultSearchPlacementName ) throws IOException {
48
46
// TRY DIFFERENT PAGINATION PARAMETERS HERE:
49
47
int pageSize = 6 ;
50
48
String queryPhrase = "Hoodie" ;
@@ -63,15 +61,17 @@ public static SearchResponse getSearchResponse(String defaultSearchPlacementName
63
61
.build ();
64
62
System .out .println ("Search request: " + searchRequest );
65
63
64
+ // Initialize client that will be used to send requests. This client only
65
+ // needs to be created once, and can be reused for multiple requests. After
66
+ // completing all of your requests, call the "close" method on the client to
67
+ // safely clean up any remaining background resources.
66
68
try (SearchServiceClient client = SearchServiceClient .create ()) {
67
69
SearchResponse searchResponseFirstPage = client .search (searchRequest ).getPage ().getResponse ();
68
70
System .out .println ("Search response: " + searchResponseFirstPage );
69
71
70
72
// PASTE CALL WITH NEXT PAGE TOKEN HERE:
71
73
72
74
// PASTE CALL WITH OFFSET HERE:
73
-
74
- return searchResponseFirstPage ;
75
75
}
76
76
}
77
77
}
0 commit comments