@Test public void parsesFilteredFacetResults() throws Exception { final FilteredFacetResult filteredFacet = searchResult.getFilteredFacetResult(FILTERED_FACET_KEY); assertThat(filteredFacet.getCount()).isEqualTo(2); }
@Test public void filteredFacetsSupportsAlias() throws Exception { final String alias = "my-facet"; final FilteredFacetExpression<ProductProjection> facetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).withAlias(alias).onlyTerm("blue"); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr); testResult(search, result -> { assertThat(facetExpr.resultPath()).isEqualTo(alias); assertThat(result.getFacetResult(facetExpr).getCount()).isEqualTo(2); }); }
@Test public void filteredFacetsAreParsed() throws Exception { final FilteredFacetExpression<ProductProjection> facetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).onlyTerm("blue"); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr); testResult(search, result -> { final FilteredFacetResult filteredFacetResult = result.getFacetResult(facetExpr); assertThat(filteredFacetResult.getCount()).isEqualTo(2); }); }
@Test public void termFacetsSupportsAlias() throws Exception { final String allFacetAlias = "my-facet"; final String blueFacetAlias = "my-blue-facet"; final TermFacetExpression<ProductProjection> allFacetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).withAlias(allFacetAlias).allTerms(); final FilteredFacetExpression<ProductProjection> blueFacetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).withAlias(blueFacetAlias).onlyTerm("blue"); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacets(allFacetExpr) .plusFacets(blueFacetExpr); testResult(search, result -> { final TermFacetResult allFacetResult = result.getFacetResult(allFacetExpr); final FilteredFacetResult blueFacetResult = result.getFilteredFacetResult(blueFacetAlias); assertThat(allFacetExpr.resultPath()).isEqualTo(allFacetAlias); assertThat(blueFacetExpr.resultPath()).isEqualTo(blueFacetAlias); assertThat(allFacetResult.getTerms()).isEqualTo(asList(TermStats.of("blue", 2L), TermStats.of("red", 1L))); assertThat(blueFacetResult.getCount()).isEqualTo(2); }); }
@Test public void facet() { final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-2-3"); final List<String> categoryIds3 = getCategoryIds("B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusFacets(m -> m.categories().id().withAlias("productsInA").onlyTermSubtree(getCategoryIds("A"))) .plusFacets(m -> m.categories().id().withAlias("productsInB").onlyTermSubtree(getCategoryIds("B"))) .plusFacets(m -> m.categories().id().withAlias("productsInAorB").onlyTermSubtree(getCategoryIds("A", "B"))) .plusFacets(m -> m.categories().id().withAlias("productsInC2").onlyTermSubtree(getCategoryIds("C-2"))) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); final PagedSearchResult<ProductProjection> pagedSearchResult = client().executeBlocking(request); assertThat(pagedSearchResult.getFilteredFacetResult("productsInA").getCount()).isEqualTo(2); assertThat(pagedSearchResult.getFilteredFacetResult("productsInB").getCount()).isEqualTo(3); assertThat(pagedSearchResult.getFilteredFacetResult("productsInAorB").getCount()).isEqualTo(3); assertThat(pagedSearchResult.getFilteredFacetResult("productsInC2").getCount()).isEqualTo(1); }); }); }); }); }