T
- type of the resourcepublic interface ProductCategoriesIdTermFacetSearchModel<T> extends TermFacetSearchModel<T,String>
The code example use the following tree for explanation
├── A
│ ├── A-1
│ │ ├── A-1-1
│ │ ├── A-1-2
│ │ └── A-1-3
│ ├── A-2
│ │ ├── A-2-1
│ │ ├── A-2-2
│ │ └── A-2-3
│ └── A-3
│ ├── A-3-1
│ ├── A-3-2
│ └── A-3-3
├── B
│ ├── B-1
│ │ ├── B-1-1
│ │ ├── B-1-2
│ │ └── B-1-3
│ ├── B-2
│ │ ├── B-2-1
│ │ ├── B-2-2
│ │ └── B-2-3
│ └── B-3
│ ├── B-3-1
│ ├── B-3-2
│ └── B-3-3
└── C
├── C-1
│ ├── C-1-1
│ ├── C-1-2
│ └── C-1-3
├── C-2
│ ├── C-2-1
│ ├── C-2-2
│ └── C-2-3
└── C-3
├── C-3-1
├── C-3-2
└── C-3-3
Modifier and Type | Method and Description |
---|---|
FilteredFacetExpression<T> |
onlyTerm(Iterable<String> values)
Generates an expression to obtain the facets of the attribute for only the given values.
|
FilteredFacetExpression<T> |
onlyTerm(String value)
Generates an expression to obtain the facet of the attribute for only the given value.
|
FilteredFacetExpression<T> |
onlyTermSubtree(Iterable<String> categoryIds)
|
FilteredFacetExpression<T> |
onlyTermSubtree(String categoryId) |
ProductCategoriesIdTermFacetSearchModel<T> |
withAlias(String alias)
Allows to set an alias to identify the facet.
|
ProductCategoriesIdTermFacetSearchModel<T> |
withCountingProducts(Boolean isCountingProducts)
Allows to enable/disable the counting of products.
|
of, onlyTermAsString
allTerms, getAlias, getSearchModel, isCountingProducts
FilteredFacetExpression<T> onlyTerm(String value)
FacetSearchModel
onlyTerm
in interface FacetSearchModel<T,String>
onlyTerm
in interface TermFacetSearchModel<T,String>
value
- the value from which to obtain the facetFilteredFacetExpression<T> onlyTerm(Iterable<String> values)
FacetSearchModel
onlyTerm
in interface FacetSearchModel<T,String>
onlyTerm
in interface TermFacetSearchModel<T,String>
values
- the values from which to obtain the facetsProductCategoriesIdTermFacetSearchModel<T> withAlias(String alias)
FacetSearchModel
withAlias
in interface FacetSearchModel<T,String>
withAlias
in interface TermFacetSearchModel<T,String>
alias
- the identifier to use for the facetProductCategoriesIdTermFacetSearchModel<T> withCountingProducts(Boolean isCountingProducts)
FacetSearchModel
withCountingProducts
in interface FacetSearchModel<T,String>
withCountingProducts
in interface TermFacetSearchModel<T,String>
isCountingProducts
- whether to count products or notFilteredFacetExpression<T> onlyTermSubtree(String categoryId)
FilteredFacetExpression<T> onlyTermSubtree(Iterable<String> categoryIds)
final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-2-3"); final List<String> categoryIds3 = getCategoryIds("B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusFacets(m -> m.categories().id().withAlias("productsInA").onlyTermSubtree(getCategoryIds("A"))) .plusFacets(m -> m.categories().id().withAlias("productsInB").onlyTermSubtree(getCategoryIds("B"))) .plusFacets(m -> m.categories().id().withAlias("productsInAorB").onlyTermSubtree(getCategoryIds("A", "B"))) .plusFacets(m -> m.categories().id().withAlias("productsInC2").onlyTermSubtree(getCategoryIds("C-2"))) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); final PagedSearchResult<ProductProjection> pagedSearchResult = client().executeBlocking(request); assertThat(pagedSearchResult.getFilteredFacetResult("productsInA").getCount()).isEqualTo(2); assertThat(pagedSearchResult.getFilteredFacetResult("productsInB").getCount()).isEqualTo(3); assertThat(pagedSearchResult.getFilteredFacetResult("productsInAorB").getCount()).isEqualTo(3); assertThat(pagedSearchResult.getFilteredFacetResult("productsInC2").getCount()).isEqualTo(1); }); }); }); });
See the test code.
categoryIds
- the IDs of the category the procuct belongs to directly or through a child