public TermFacetSearchModel<ProductProjection, String> ofStringSet(final String attributeName) { return ofString(attributeName); }
public TermFacetSearchModel<ProductProjection, String> ofStringSet(final String attributeName) { return ofString(attributeName); }
public TermFacetSearchModel<ProductProjection, String> ofStringSet(final String attributeName) { return ofString(attributeName); }
@Test public void canAccessTextCustomAttributes() throws Exception { final String attrName = "brand"; assertThat(FACET_ATTR.ofString(attrName).allTerms().expression()).isEqualTo("variants.attributes.brand"); assertThat(FILTER_ATTR.ofString(attrName).is("Apple")).extracting(expression()).containsExactly("variants.attributes.brand:\"Apple\""); assertThat(SORT_ATTR.ofString(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.brand asc.max"); }
@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 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 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 onTextAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofString(ATTR_NAME_TEXT).allTerms(), termStats -> assertThat(termStats).containsOnly( TermStats.of(TEXT_FOO, 1L), TermStats.of(TEXT_BAR, 1L))); }
@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 responseContainsTermFacetsForAttributes() 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 -> assertThat(result.getFacetResult(facetExpr).getTerms()).containsOnly(TermStats.of("blue", 2L), TermStats.of("red", 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))); }