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