@Test public void resultsAndFacetsAreFiltered() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacets(SIZE_FACETED_SEARCH.facetExpression()) .plusFacets(COLOR_FACETED_SEARCH.facetExpression()) .plusResultFilters(COLOR_FACETED_SEARCH.filterExpressions()) .plusFacetFilters(COLOR_FACETED_SEARCH.filterExpressions()); 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))); }
@Test public void onlyResultsAreFiltered() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacets(SIZE_FACETED_SEARCH.facetExpression()) .plusFacets(COLOR_FACETED_SEARCH.facetExpression()) .plusResultFilters(COLOR_FACETED_SEARCH.filterExpressions()); 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), TermStats.of("38.0", 1L), TermStats.of("40.0", 1L), TermStats.of("42.0", 1L), TermStats.of("44.0", 1L), TermStats.of("46.0", 1L))); }
@Test public void facetedSearchVerboseExample() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacets(facet -> facet.allVariants().attribute().ofString(ATTR_NAME_COLOR).allTerms()) .plusFacets(facet -> facet.allVariants().attribute().ofNumber(ATTR_NAME_SIZE).allTerms()) .plusResultFilters(filter -> filter.allVariants().attribute().ofString(ATTR_NAME_COLOR).is("red")) .plusFacetFilters(filter -> filter.allVariants().attribute().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))); }
@Test public void searchByCount() { final ProductProjectionSearch projectionSearch = ProductProjectionSearch.ofStaged()//in prod it would be current .withResultFilters(m -> m.reviewRatingStatistics().count().isGreaterThanOrEqualTo(new BigDecimal(2))) .plusResultFilters(m -> m.reviewRatingStatistics().highestRating().isGreaterThanOrEqualTo(new BigDecimal(2))) .plusResultFilters(m -> m.reviewRatingStatistics().lowestRating().isGreaterThanOrEqualTo(new BigDecimal(0))) .plusFacets(m -> m.reviewRatingStatistics().count().allRanges()) .plusFacets(m -> m.reviewRatingStatistics().highestRating().allRanges()) .plusFacets(m -> m.reviewRatingStatistics().lowestRating().allRanges()) ; assertEventually(Duration.ofSeconds(60), Duration.ofMillis(100), () -> { softAssert(soft -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(projectionSearch); soft.assertThat(res.getCount()).isGreaterThanOrEqualTo(3); final RangeFacetResult countFacets = (RangeFacetResult) res.getFacetResult("reviewRatingStatistics.count"); soft.assertThat(countFacets.getRanges().get(1).getSum()).as("count facets").isEqualTo("60.0"); final RangeFacetResult lowestRatingFacets = (RangeFacetResult) res.getFacetResult("reviewRatingStatistics.lowestRating"); soft.assertThat(lowestRatingFacets.getRanges().get(1).getSum()).as("lowestRating facets").isEqualTo("0.0"); final RangeFacetResult highestRatingFacets = (RangeFacetResult) res.getFacetResult("reviewRatingStatistics.highestRating"); soft.assertThat(highestRatingFacets.getRanges().get(1).getSum()).as("highestRating facets").isEqualTo("14.0"); }); }); }