Search in sources :

Example 11 with SearchResponse

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

the class SearchWithFacetSpecTest method testSearchWithFacetSpec.

@Test
public void testSearchWithFacetSpec() throws IOException {
    SearchResponse response = SearchWithFacetSpec.getSearchResponse(defaultSearchPlacementName);
    Assert.assertEquals(10, response.getResultsCount());
    String productTitle = response.getResults(0).getProduct().getTitle();
    Assert.assertTrue(productTitle.contains("Tee"));
    Assert.assertEquals("colorFamilies", response.getFacets(0).getKey());
}
Also used : SearchResponse(com.google.cloud.retail.v2.SearchResponse) Test(org.junit.Test)

Example 12 with SearchResponse

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

the class SearchWithFiltering method getSearchResponse.

public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
    // TRY DIFFERENT FILTER EXPRESSIONS HERE:
    String filter = "(colorFamilies: ANY(\"Black\"))";
    String queryPhrase = "Tee";
    int pageSize = 10;
    String visitorId = UUID.randomUUID().toString();
    SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setVisitorId(visitorId).setQuery(queryPhrase).setPageSize(pageSize).setFilter(filter).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 13 with SearchResponse

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

the class SearchWithFilteringTest method TestSearchWithFiltering.

@Test
public void TestSearchWithFiltering() throws IOException {
    SearchResponse response = SearchWithFiltering.getSearchResponse(defaultSearchPlacementName);
    Assert.assertEquals(10, response.getResultsCount());
    String productTitle = response.getResults(0).getProduct().getTitle();
    Assert.assertTrue(productTitle.contains("Google Black Cloud Tee"));
    Assert.assertTrue(response.getResults(0).getProduct().getColorInfo().getColorFamilies(0).contains("Black"));
    Assert.assertEquals(16, response.getTotalSize());
}
Also used : SearchResponse(com.google.cloud.retail.v2.SearchResponse) Test(org.junit.Test)

Example 14 with SearchResponse

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

the class SearchWithOrderingTest method TestSearchWithOrdering.

@Test
public void TestSearchWithOrdering() throws IOException {
    SearchResponse response = SearchWithOrdering.getSearchResponse(defaultSearchPlacementName);
    Assert.assertEquals(10, response.getResultsCount());
    String productTitle = response.getResults(3).getProduct().getTitle();
    Assert.assertTrue(productTitle.contains("Hoodie"));
    Assert.assertEquals(39, response.getResults(0).getProduct().getPriceInfo().getPrice(), 0);
}
Also used : SearchResponse(com.google.cloud.retail.v2.SearchResponse) Test(org.junit.Test)

Example 15 with SearchResponse

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

the class SearchWithQueryExpansionSpecTest method testSearchWithQueryExpansionSpec.

@Test
public void testSearchWithQueryExpansionSpec() throws IOException {
    SearchResponse response = SearchWithQueryExpansionSpec.getSearchResponse(defaultSearchPlacementName);
    Assert.assertEquals(10, response.getResultsCount());
    Assert.assertTrue(response.getResults(0).getProduct().getTitle().contains("Google Youth Hero Tee Grey"));
    Assert.assertFalse(response.getResults(2).getProduct().getTitle().contains("Google Youth Hero Tee Grey"));
    Assert.assertTrue(response.getQueryExpansionInfo().getExpandedQuery());
}
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