use of com.google.cloud.retail.v2.SearchRequest.BoostSpec in project java-retail by googleapis.
the class SearchWithBoostSpec method getSearchResponse.
public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
// TRY DIFFERENT CONDITIONS HERE:
String searchQuery = "Tee";
String condition = "(colorFamilies: ANY(\"Blue\"))";
float boost = 0.0f;
int pageSize = 10;
String visitorId = UUID.randomUUID().toString();
BoostSpec boostSpec = BoostSpec.newBuilder().addConditionBoostSpecs(ConditionBoostSpec.newBuilder().setCondition(condition).setBoost(boost).build()).build();
SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(searchQuery).setVisitorId(visitorId).setBoostSpec(boostSpec).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;
}
}
Aggregations