Search in sources :

Example 1 with FacetSpec

use of com.google.cloud.retail.v2.SearchRequest.FacetSpec in project java-retail by googleapis.

the class SearchWithFacetSpec method getSearchResponse.

public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
    // TRY DIFFERENT CONDITIONS HERE:
    String searchQuery = "Tee";
    String facetKeyParam = "colorFamilies";
    int pageSize = 10;
    String visitorId = UUID.randomUUID().toString();
    FacetKey facetKey = FacetKey.newBuilder().setKey(facetKeyParam).build();
    FacetSpec facetSpec = FacetSpec.newBuilder().setFacetKey(facetKey).build();
    SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(searchQuery).setVisitorId(visitorId).addFacetSpecs(facetSpec).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 : SearchServiceClient(com.google.cloud.retail.v2.SearchServiceClient) SearchRequest(com.google.cloud.retail.v2.SearchRequest) FacetSpec(com.google.cloud.retail.v2.SearchRequest.FacetSpec) FacetKey(com.google.cloud.retail.v2.SearchRequest.FacetSpec.FacetKey) SearchResponse(com.google.cloud.retail.v2.SearchResponse)

Aggregations

SearchRequest (com.google.cloud.retail.v2.SearchRequest)1 FacetSpec (com.google.cloud.retail.v2.SearchRequest.FacetSpec)1 FacetKey (com.google.cloud.retail.v2.SearchRequest.FacetSpec.FacetKey)1 SearchResponse (com.google.cloud.retail.v2.SearchResponse)1 SearchServiceClient (com.google.cloud.retail.v2.SearchServiceClient)1