T
- type of the resourcepublic interface ProductCategoriesIdTermFilterSearchModel<T> extends ExistsAndMissingFilterSearchModelSupport<T>, TermFilterSearchModel<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 |
---|---|
List<FilterExpression<T>> |
containsAll(Iterable<String> categoryIds)
Creates filters for a product which needs to be in all categories directly (
categoryIds ). |
List<FilterExpression<T>> |
containsAllIncludingSubtrees(Iterable<String> categoryIds)
Creates filters for a product which needs to be in all categories or its descendants.
|
List<FilterExpression<T>> |
containsAny(Iterable<String> categoryIds)
Creates filters for a product which needs to be in any of the given categories directly (
categoryIds ). |
List<FilterExpression<T>> |
containsAnyIncludingSubtrees(Iterable<String> categoryIds)
Creates filters for a product which needs to be in any of the given categories or its descendants.
|
List<FilterExpression<T>> |
is(String categoryId)
Creates filters for a product which should directly belong to the given category in
categoryId . |
List<FilterExpression<T>> |
isIn(Iterable<String> categoryIds)
Creates filters for a product which needs to be in any of the given categories directly (
categoryIds ). |
List<FilterExpression<T>> |
isInSubtree(String categoryId)
Creates filters for a product which is in a category and its descendants.
|
List<FilterExpression<T>> |
isInSubtreeOrInCategory(Iterable<String> categoryIdsSubtree,
Iterable<String> categoryIdsDirectly)
Creates filters for a product which is in certain category trees (
categoryIdsSubtree ) or direct categories (). |
exists, missing
containsAllAsString, containsAnyAsString, of
getSearchModel
List<FilterExpression<T>> containsAll(Iterable<String> categoryIds)
Creates filters for a product which needs to be in all categories directly (categoryIds
). Does not include the child categories.
final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-1"); final List<String> categoryIds3 = getCategoryIds("A", "B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().containsAll(categoryIds1)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1)); }); }); }); });
See the test code.
containsAll
in interface FilterSearchModel<T,String>
containsAll
in interface TermFilterSearchModel<T,String>
categoryIds
- the ID of the category which the products belongs to excluding subcategoriesList<FilterExpression<T>> containsAny(Iterable<String> categoryIds)
Creates filters for a product which needs to be in any of the given categories directly (categoryIds
). Does not include the child categories.
isIn(Iterable)
.
final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-1"); final List<String> categoryIds3 = getCategoryIds("A", "B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().containsAny(categoryIds1)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1, product2, product3)); }); }); }); });
See the test code.
containsAny
in interface FilterSearchModel<T,String>
containsAny
in interface TermFilterSearchModel<T,String>
categoryIds
- the IDs of categories which the product should belong to at least to one of themisIn(Iterable)
List<FilterExpression<T>> is(String categoryId)
Creates filters for a product which should directly belong to the given category in categoryId
.
withCategoryAndParentCategory(client(), (Category cat, Category parent) -> { withProduct(client(), builder -> builder.categoriesAsObjectList(singletonList(cat)), product -> { final String parentId = parent.getId(); assertThat(product.getMasterData().getStaged().getCategories()) .contains(cat.toReference()) .doesNotContain(parent.toReference()); assertEventually(() -> { //search for products directly in parent category final ProductProjectionSearch requestForDirectCategories = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().is(parentId)); assertThat(client().executeBlocking(requestForDirectCategories).getResults()).isEmpty(); //search for products in parent category or its descendants final ProductProjectionSearch requestForTree = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().isInSubtree(parentId)); final List<ProductProjection> results = client().executeBlocking(requestForTree).getResults(); assertThat(results).hasSize(1); }); }); });
See the test code.
final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-1"); final List<String> categoryIds3 = getCategoryIds("A", "B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().containsAny(getCategoryIds("B-1"))) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1, product2)); }); }); }); });
See the test code.
is
in interface FilterSearchModel<T,String>
is
in interface TermFilterSearchModel<T,String>
categoryId
- the ID of the category which the products belong to including subcategoriesList<FilterExpression<T>> isIn(Iterable<String> categoryIds)
Creates filters for a product which needs to be in any of the given categories directly (categoryIds
). Does not include the child categories.
containsAny(Iterable)
.
final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-1"); final List<String> categoryIds3 = getCategoryIds("A", "B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().containsAny(categoryIds1)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1, product2, product3)); }); }); }); });
See the test code.
isIn
in interface FilterSearchModel<T,String>
isIn
in interface TermFilterSearchModel<T,String>
categoryIds
- the IDs of categories which the product should belong to at least to one of themcontainsAny(Iterable)
List<FilterExpression<T>> containsAnyIncludingSubtrees(Iterable<String> categoryIds)
Creates filters for a product which needs to be in any of the given categories or its descendants.
final List<String> categoryIds1 = getCategoryIds("A", "B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("A", "B-1"); final List<String> categoryIds3 = getCategoryIds("A", "B", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().containsAnyIncludingSubtrees(getCategoryIds("C-2"))) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1)); }); }); }); });
See the test code.
categoryIds
- the IDs of categories which the product should belong to at least to one of themisIn(Iterable)
List<FilterExpression<T>> containsAllIncludingSubtrees(Iterable<String> categoryIds)
Creates filters for a product which needs to be in all categories or its descendants.
final List<String> categoryIds1 = getCategoryIds("B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("B-1-2", "C-1-3"); final List<String> categoryIds3 = getCategoryIds("B-3", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().containsAllIncludingSubtrees(getCategoryIds("C", "B-1"))) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1, product2)); }); }); }); });
See the test code.
categoryIds
- the ID of the category which the products belongs to including subcategoriesList<FilterExpression<T>> isInSubtree(String categoryId)
Creates filters for a product which is in a category and its descendants.
withCategoryAndParentCategory(client(), (Category cat, Category parent) -> { withProduct(client(), builder -> builder.categoriesAsObjectList(singletonList(cat)), product -> { final String parentId = parent.getId(); assertThat(product.getMasterData().getStaged().getCategories()) .contains(cat.toReference()) .doesNotContain(parent.toReference()); assertEventually(() -> { //search for products directly in parent category final ProductProjectionSearch requestForDirectCategories = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().is(parentId)); assertThat(client().executeBlocking(requestForDirectCategories).getResults()).isEmpty(); //search for products in parent category or its descendants final ProductProjectionSearch requestForTree = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.categories().id().isInSubtree(parentId)); final List<ProductProjection> results = client().executeBlocking(requestForTree).getResults(); assertThat(results).hasSize(1); }); }); });
See the test code.
final List<String> categoryIds1 = getCategoryIds("B-1", "C-2-2"); final List<String> categoryIds2 = getCategoryIds("B-1-2", "C-1-3"); final List<String> categoryIds3 = getCategoryIds("B-3", "C"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> { final String categoryId = getCategoryIds("B-1").get(0); return m.categories().id().isInSubtree(categoryId); }) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product1, product2)); }); }); }); });
See the test code.
categoryId
- the ID of the category which the products belong to including subcategoriesList<FilterExpression<T>> isInSubtreeOrInCategory(Iterable<String> categoryIdsSubtree, Iterable<String> categoryIdsDirectly)
Creates filters for a product which is in certain category trees (categoryIdsSubtree
) or direct categories ().
final List<String> categoryIds1 = getCategoryIds("C-2-2"); final List<String> categoryIds2 = getCategoryIds("C-1-3"); final List<String> categoryIds3 = getCategoryIds("B-3"); withProductInCategories(client(), categoryIds1, (Product product1) -> { withProductInCategories(client(), categoryIds2, (Product product2) -> { withProductInCategories(client(), categoryIds3, (Product product3) -> { assertEventually(() -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> { final List<String> categoryIdsSubtree = getCategoryIds("B");//somehow in B final List<String> categoryIdsDirectly = getCategoryIds("C-1-3");//but directly in C-1-3 return m.categories().id().isInSubtreeOrInCategory(categoryIdsSubtree, categoryIdsDirectly); }) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))); assertThat(client().executeBlocking(request)).has(onlyProducts(product2, product3)); }); }); }); });
See the test code.
categoryIdsSubtree
- IDs of categories which the product belongs directly or indirectly tocategoryIdsDirectly
- IDs of categories which the product belongs directly to