Search in sources :

Example 1 with SearchResponse

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

the class SearchWithPaginationTest method TestSearchWithOrdering.

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

Example 2 with SearchResponse

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

the class SearchServiceClientTest method searchTest.

@Test
public void searchTest() throws Exception {
    SearchResponse.SearchResult responsesElement = SearchResponse.SearchResult.newBuilder().build();
    SearchResponse expectedResponse = SearchResponse.newBuilder().setNextPageToken("").addAllResults(Arrays.asList(responsesElement)).build();
    mockSearchService.addResponse(expectedResponse);
    SearchRequest request = SearchRequest.newBuilder().setPlacement("placement1792938725").setBranch(BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString()).setQuery("query107944136").setVisitorId("visitorId1880545833").setUserInfo(UserInfo.newBuilder().build()).setPageSize(883849137).setPageToken("pageToken873572522").setOffset(-1019779949).setFilter("filter-1274492040").setCanonicalFilter("canonicalFilter-722283124").setOrderBy("orderBy-1207110587").addAllFacetSpecs(new ArrayList<SearchRequest.FacetSpec>()).setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build()).setBoostSpec(SearchRequest.BoostSpec.newBuilder().build()).setQueryExpansionSpec(SearchRequest.QueryExpansionSpec.newBuilder().build()).addAllVariantRollupKeys(new ArrayList<String>()).addAllPageCategories(new ArrayList<String>()).build();
    SearchPagedResponse pagedListResponse = client.search(request);
    List<SearchResponse.SearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSearchService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SearchRequest actualRequest = ((SearchRequest) actualRequests.get(0));
    Assert.assertEquals(request.getPlacement(), actualRequest.getPlacement());
    Assert.assertEquals(request.getBranch(), actualRequest.getBranch());
    Assert.assertEquals(request.getQuery(), actualRequest.getQuery());
    Assert.assertEquals(request.getVisitorId(), actualRequest.getVisitorId());
    Assert.assertEquals(request.getUserInfo(), actualRequest.getUserInfo());
    Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
    Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
    Assert.assertEquals(request.getOffset(), actualRequest.getOffset());
    Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
    Assert.assertEquals(request.getCanonicalFilter(), actualRequest.getCanonicalFilter());
    Assert.assertEquals(request.getOrderBy(), actualRequest.getOrderBy());
    Assert.assertEquals(request.getFacetSpecsList(), actualRequest.getFacetSpecsList());
    Assert.assertEquals(request.getDynamicFacetSpec(), actualRequest.getDynamicFacetSpec());
    Assert.assertEquals(request.getBoostSpec(), actualRequest.getBoostSpec());
    Assert.assertEquals(request.getQueryExpansionSpec(), actualRequest.getQueryExpansionSpec());
    Assert.assertEquals(request.getVariantRollupKeysList(), actualRequest.getVariantRollupKeysList());
    Assert.assertEquals(request.getPageCategoriesList(), actualRequest.getPageCategoriesList());
    Assert.assertEquals(request.getSearchMode(), actualRequest.getSearchMode());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) SearchPagedResponse(com.google.cloud.retail.v2.SearchServiceClient.SearchPagedResponse) Test(org.junit.Test)

Example 3 with SearchResponse

use of com.google.cloud.retail.v2.SearchResponse 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 4 with SearchResponse

use of com.google.cloud.retail.v2.SearchResponse 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 5 with SearchResponse

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

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