@Test public void parsesTermFacetResults() throws Exception { final TermFacetResult termFacet = searchResult.getTermFacetResult(TERM_FACET_KEY); assertThat(termFacet.getMissing()).isEqualTo(44); assertThat(termFacet.getTotal()).isEqualTo(6937); assertThat(termFacet.getOther()).isEqualTo(0); assertThat(termFacet.getTerms()).hasSize(21); assertThat(termFacet.getTerms().get(2)).isEqualTo(TermStats.of("4B432E_1", 585L)); }
@Test public void simpleFacetsAreParsed() throws Exception { final TermFacetExpression<ProductProjection> facetExpr = TermFacetExpression.of("variants.attributes." + ATTR_NAME_COLOR); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr); testResult(search, result -> { final TermFacetResult termFacetResult = result.getFacetResult(facetExpr); assertThat(termFacetResult.getMissing()).isGreaterThanOrEqualTo(3); assertThat(termFacetResult.getTotal()).isEqualTo(3); assertThat(termFacetResult.getOther()).isEqualTo(0); assertThat(termFacetResult.getTerms()).isEqualTo(asList(TermStats.of("blue", 2L), TermStats.of("red", 1L))); }); }
@Test public void termFacetsAreParsed() throws Exception { final TermFacetExpression<ProductProjection> facetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).allTerms(); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr); testResult(search, result -> { final TermFacetResult termFacetResult = result.getFacetResult(facetExpr); assertThat(termFacetResult.getMissing()).isGreaterThanOrEqualTo(3); assertThat(termFacetResult.getTotal()).isEqualTo(3); assertThat(termFacetResult.getOther()).isEqualTo(0); assertThat(termFacetResult.getTerms()).isEqualTo(asList(TermStats.of("blue", 2L), TermStats.of("red", 1L))); }); }
@Test public void facetAndFilter() { final ReviewRatingStatisticsFacetedSearchSearchModel<ProductProjection> reviewRatingsModel = ProductProjectionSearchModel.of().facetedSearch().reviewRatingStatistics(); final TermFacetedSearchExpression<ProductProjection> count = reviewRatingsModel.count().is("20"); final TermFacetedSearchExpression<ProductProjection> averageRating = reviewRatingsModel.averageRating().is("2.7"); final TermFacetedSearchExpression<ProductProjection> highestRating = reviewRatingsModel.highestRating().is(String.valueOf(HIGHEST_RATING)); final TermFacetedSearchExpression<ProductProjection> lowestRating = reviewRatingsModel.lowestRating().is(String.valueOf(LOWEST_RATING)); final ProductProjectionSearch productProjectionSearch = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().is(product.getId())) .plusFacetedSearch(asList(count, averageRating, highestRating, lowestRating)); assertEventually(() -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(productProjectionSearch); final List<ProductProjection> productProjectionList = result.getResults(); assertThat(productProjectionList).isNotEmpty(); assertThat(productProjectionList.get(0).getId()).isEqualTo(product.getId()); assertThat(result.getFacetResult(count).getTotal()).as("count facet").isEqualTo(1L); assertThat(result.getFacetResult(averageRating).getTotal()).as("averageRating facet").isEqualTo(1L); assertThat(result.getFacetResult(highestRating).getTotal()).as("highestRating facet").isEqualTo(1L); assertThat(result.getFacetResult(lowestRating).getTotal()).as("lowestRating facet").isEqualTo(1L); }); }