use of com.google.cloud.retail.v2.SearchResponse in project java-retail by googleapis.
the class SearchWithOrdering method getSearchResponse.
public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
// TRY DIFFERENT ORDER BY EXPRESSION HERE:
String order = "price desc";
String queryPhrase = "Hoodie";
int pageSize = 10;
String visitorId = UUID.randomUUID().toString();
SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(queryPhrase).setOrderBy(order).setVisitorId(visitorId).setPageSize(pageSize).build();
System.out.println("Search request: " + searchRequest);
try (SearchServiceClient client = SearchServiceClient.create()) {
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
System.out.println("Search response: " + searchResponse);
return searchResponse;
}
}
use of com.google.cloud.retail.v2.SearchResponse in project java-retail by googleapis.
the class SearchWithPagination method getSearchResponse.
public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
// TRY DIFFERENT PAGINATION PARAMETERS HERE:
int pageSize = 6;
String queryPhrase = "Hoodie";
int offset = 0;
String pageToken = "";
String visitorId = UUID.randomUUID().toString();
SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setVisitorId(visitorId).setQuery(queryPhrase).setPageSize(pageSize).setOffset(offset).setPageToken(pageToken).build();
System.out.println("Search request: " + searchRequest);
try (SearchServiceClient client = SearchServiceClient.create()) {
SearchResponse searchResponseFirstPage = client.search(searchRequest).getPage().getResponse();
System.out.println("Search response: " + searchResponseFirstPage);
return searchResponseFirstPage;
}
}
use of com.google.cloud.retail.v2.SearchResponse in project java-retail by googleapis.
the class SearchWithQueryExpansionSpec method getSearchResponse.
public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
// TRY DIFFERENT QUERY EXPANSION CONDITION HERE:
Condition condition = Condition.AUTO;
int pageSize = 10;
String queryPhrase = "Google Youth Hero Tee Grey";
String visitorId = UUID.randomUUID().toString();
QueryExpansionSpec queryExpansionSpec = QueryExpansionSpec.newBuilder().setCondition(condition).build();
SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(queryPhrase).setVisitorId(visitorId).setQueryExpansionSpec(queryExpansionSpec).setPageSize(pageSize).build();
System.out.println("Search request: " + searchRequest);
try (SearchServiceClient client = SearchServiceClient.create()) {
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
System.out.println("Search response: " + searchResponse);
return searchResponse;
}
}
use of com.google.cloud.retail.v2.SearchResponse in project java-retail by googleapis.
the class SearchSimpleQueryTest method testSearchSimpleQuery.
@Test
public void testSearchSimpleQuery() throws IOException {
SearchResponse response = SearchSimpleQuery.getSearchResponse(defaultSearchPlacementName);
Assert.assertEquals(10, response.getResultsCount());
String productTitle = response.getResults(0).getProduct().getTitle();
Assert.assertTrue(productTitle.contains("Hoodie"));
}
use of com.google.cloud.retail.v2.SearchResponse in project java-retail by googleapis.
the class SearchWithBoostSpecTest method testSearchWithBoostSpec.
@Test
public void testSearchWithBoostSpec() throws IOException {
SearchResponse response = SearchWithBoostSpec.getSearchResponse(defaultSearchPlacementName);
Assert.assertEquals(10, response.getResultsCount());
String productTitle = response.getResults(0).getProduct().getTitle();
Assert.assertTrue(productTitle.contains("Tee"));
}
Aggregations