Search in sources :

Example 1 with QueryExpansionSpec

use of com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec 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;
    }
}
Also used : Condition(com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec.Condition) SearchServiceClient(com.google.cloud.retail.v2.SearchServiceClient) SearchRequest(com.google.cloud.retail.v2.SearchRequest) QueryExpansionSpec(com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec) SearchResponse(com.google.cloud.retail.v2.SearchResponse)

Aggregations

SearchRequest (com.google.cloud.retail.v2.SearchRequest)1 QueryExpansionSpec (com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec)1 Condition (com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec.Condition)1 SearchResponse (com.google.cloud.retail.v2.SearchResponse)1 SearchServiceClient (com.google.cloud.retail.v2.SearchServiceClient)1