Search in sources :

Example 6 with SearchResponse

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

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

Example 8 with SearchResponse

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;
    }
}
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)

Example 9 with 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"));
}
Also used : SearchResponse(com.google.cloud.retail.v2.SearchResponse) Test(org.junit.Test)

Example 10 with SearchResponse

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"));
}
Also used : SearchResponse(com.google.cloud.retail.v2.SearchResponse) Test(org.junit.Test)

Aggregations

SearchResponse (com.google.cloud.retail.v2.SearchResponse)14 Test (org.junit.Test)8 SearchRequest (com.google.cloud.retail.v2.SearchRequest)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 SearchPagedResponse (com.google.cloud.retail.v2.SearchServiceClient.SearchPagedResponse)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 MediaList (com.sonos.services._1.MediaList)1 SearchResponse (com.sonos.services._1.SearchResponse)1 ArrayList (java.util.ArrayList)1 GraphAuth (me.michaeldick.sonosonedrive.model.GraphAuth)1