@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); }); }
@Test public void facetedSearchExample() throws Exception { final ProductAttributeFacetedSearchSearchModel attributeModel = ProductProjectionSearchModel.of().facetedSearch().allVariants().attribute(); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacetedSearch(attributeModel.ofNumber(ATTR_NAME_SIZE).allTerms()) .plusFacetedSearch(attributeModel.ofString(ATTR_NAME_COLOR).is("red")); testResult(search, ids -> assertThat(ids).containsOnly(product2.getId()), colors -> assertThat(colors).containsOnly(TermStats.of("blue", 2L), TermStats.of("red", 1L)), sizes -> assertThat(sizes).containsOnly(TermStats.of("36.0", 1L))); }