Search in sources :

Example 1 with SearchServiceClient

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

the class SearchSimpleQuery method getSearchResponse.

public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
    // TRY DIFFERENT QUERY PHRASES HERE:
    String queryPhrase = "Hoodie";
    String visitorId = UUID.randomUUID().toString();
    int pageSize = 10;
    SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(queryPhrase).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;
    }
}
Also used : SearchServiceClient(com.google.cloud.retail.v2.SearchServiceClient) SearchRequest(com.google.cloud.retail.v2.SearchRequest) SearchResponse(com.google.cloud.retail.v2.SearchResponse)

Example 2 with SearchServiceClient

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

Example 3 with SearchServiceClient

use of com.google.cloud.retail.v2.SearchServiceClient 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)

Example 4 with SearchServiceClient

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

Example 5 with SearchServiceClient

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

Aggregations

SearchRequest (com.google.cloud.retail.v2.SearchRequest)7 SearchResponse (com.google.cloud.retail.v2.SearchResponse)7 SearchServiceClient (com.google.cloud.retail.v2.SearchServiceClient)7 BoostSpec (com.google.cloud.retail.v2.SearchRequest.BoostSpec)1 ConditionBoostSpec (com.google.cloud.retail.v2.SearchRequest.BoostSpec.ConditionBoostSpec)1 FacetSpec (com.google.cloud.retail.v2.SearchRequest.FacetSpec)1 FacetKey (com.google.cloud.retail.v2.SearchRequest.FacetSpec.FacetKey)1 QueryExpansionSpec (com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec)1 Condition (com.google.cloud.retail.v2.SearchRequest.QueryExpansionSpec.Condition)1