@Test public void categorySubtree() { final List<String> expressionsWithoutSubtrees = ProductProjectionSearch.ofStaged().withQueryFilters(m -> m.categories().id().isIn(asList("id1", "id2"))).queryFilters().stream().map(e -> e.expression()).collect(Collectors.toList()); assertThat(expressionsWithoutSubtrees.get(0)).isEqualTo("categories.id:\"id1\",\"id2\""); final List<FilterExpression<ProductProjection>> filterExpressions = ProductProjectionSearch.ofStaged().withQueryFilters(m -> m.categories().id().isInSubtreeOrInCategory(asList("id1", "id2"), asList("id3", "id4"))).queryFilters(); final List<String> collect = filterExpressions.stream().map(e -> e.expression()).collect(Collectors.toList()); final String expected = "categories.id:subtree(\"id1\"),subtree(\"id2\"),\"id3\",\"id4\""; assertThat(collect).hasSize(1); assertThat(collect.get(0)).isEqualTo(expected); }
@Test public void isInSubtreeOrInCategory() { 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)); }); }); }); }); }