static TermStats of(final String term, final Long count) { return TermStats.of(term, count, null); } }
public static TermStats<String> of(final String term, final long count) { return new TermStats<>(term, count); } }
@Test public void parsesTermFacetResultsProductCounts() throws Exception { final TermFacetResult termFacet = searchResult.getTermFacetResult(TERM_FACET_COUNTING_PRODUCTS_KEY); assertThat(termFacet.getTerms()).hasSize(2); assertThat(termFacet.getTerms().get(0).getProductCount()).isEqualTo(372); assertThat(termFacet.getTerms().get(1).getProductCount()).isEqualTo(195); }
@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 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 onDatetimeSetAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofDateTimeSet(ATTR_NAME_DATE_TIME_SET).allTerms(), termStats -> assertThat(termStats).containsExactly( TermStats.of("2001-09-11T22:05:09.203+0000", 2L), TermStats.of("2002-10-12T23:06:10.204+0000", 1L))); }
@Test public void facetedSearchOnNumberSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofNumberSet(ATTR_NAME_NUMBER_SET).is(NUMBER_10.toPlainString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of("5.0", 2L), TermStats.of("10.0", 1L))); }
@Test public void facetedSearchOnTextSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofStringSet(ATTR_NAME_TEXT_SET).is(TEXT_BAR), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(TEXT_FOO, 2L), TermStats.of(TEXT_BAR, 1L))); }
@Test public void facetedSearchOnBooleanSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofBooleanSet(ATTR_NAME_BOOLEAN_SET).is(BOOL_FALSE), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(BOOL_TRUE, 2L), TermStats.of(BOOL_FALSE, 1L))); }
@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))); }); }