public TermFilterExistsAndMissingSearchModel<ProductProjection, String> ofStringSet(final String attributeName) { return ofString(attributeName); }
public TermFilterExistsAndMissingSearchModel<ProductProjection, String> ofStringSet(final String attributeName) { return ofString(attributeName); }
public TermFilterSearchModel<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 filterByEvilCharacterWord() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofString(ATTR_NAME_EVIL).is(EVIL_CHARACTER_WORD)); assertEventually(Duration.ofSeconds(60), Duration.ofMillis(200), () -> { final PagedSearchResult<ProductProjection> result = executeEvilSearch(search); assertThat(result.getTotal()).as("total").isEqualTo(1); }); }
private void testBlueFilter(final Function<List<FilterExpression<ProductProjection>>, ProductProjectionSearch> createSearch) { final ProductProjectionSearch search = createSearch.apply(PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).is("blue")); testResult(search, result -> { final List<ProductProjection> results = result.getResults(); final Predicate<ProductVariant> isBlue = variant -> variant.findAttribute(COLOR_ATTRIBUTE_ACCESS) .map(color -> color.equals("blue")) .orElse(false); final Condition<ProductVariant> blueVariant = new Condition<>(isBlue, "variant is blue"); assertThat(results) .flatExtracting(ProductProjection::getAllVariants) .areAtLeastOne(notMatching(blueVariant)) .areAtLeastOne(blueVariant); final List<ProductVariant> allMatchingVariants = results.stream() .flatMap(r -> r.findMatchingVariants().stream()) .collect(toList()); assertThat(allMatchingVariants).are(blueVariant); assertThat(results) .extracting(r -> r.findFirstMatchingVariant().get()) .containsOnlyElementsOf(allMatchingVariants); }); }
@Test public void onTextAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_TEXT).is(TEXT_FOO), ids -> assertThat(ids).containsOnly(product1.getId())); }
@Test public void filtersByTerm() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofString(ATTR_NAME_COLOR).is("red")); testResultIds(search, resultIds -> assertThat(resultIds).containsOnly(product2.getId())); }
.withMarkingMatchingVariants(true) .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().attribute().ofString(attributeName).is("3")); assertEventually(() -> { final Optional<ProductProjection> productProjectionOptional = client().executeBlocking(searchRequest).head();
@Test public void resultsArePaginated() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(productModel -> productModel.allVariants().attribute().ofString(ATTR_NAME_COLOR).isIn(asList("blue", "red"))) .withSort(sort -> sort.name().locale(ENGLISH).desc()) .withOffset(1L) .withLimit(1L); testResultIds(search, resultIds -> assertThat(resultIds).containsOnly(product2.getId())); }
@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))); }
@Test public void productAttribute() { checkFilter(builder -> { final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of(builder.getMasterVariant()) .attributes(AttributeDraft.of("stringfield", "hello")) .build(); return builder.masterVariant(masterVariant); }, m -> m.allVariants().attribute().ofString("stringfield")); }