public ProductVariantFacetSearchModel allVariants() { return new ProductVariantFacetSearchModel(this, "variants"); }
public MoneyFacetSearchModel<ProductProjection> price() { return moneyFacetSearchModel("price"); } }
public TermFacetSearchModel<ProductProjection, Boolean> scopedPriceDiscounted() { return booleanSearchModel("scopedPriceDiscounted").faceted(); } }
@Test public void onNumberRangedAttributes() throws Exception { testRangeStats(FACET.allVariants().attribute().ofNumber(ATTR_NAME_NUMBER).onlyGreaterThanOrEqualTo(valueOf(0)), rangeStats -> { assertThat(rangeStats.getLowerEndpoint()).isEqualTo("0.0"); assertThat(rangeStats.getUpperEndpoint()).isEqualTo(null); assertThat(rangeStats.getCount()).isEqualTo(2L); assertThat(rangeStats.getMin()).isEqualTo("5.0"); assertThat(rangeStats.getMax()).isEqualTo("10.0"); assertThat(rangeStats.getSum()).isEqualTo("15.0"); assertThat(rangeStats.getMean()).isEqualTo(7.50D); }); }
@Test public void canAccessPriceAmount() throws Exception { assertThat(FACET_MODEL.allVariants().price().centAmount().allTerms().expression()).isEqualTo("variants.price.centAmount"); assertThat(FILTER_MODEL.allVariants().price().centAmount().is(1000L)).extracting(expression()).containsExactly("variants.price.centAmount:1000"); assertThat(SORT_MODEL.allVariants().price().descWithMinValue().expression()).isEqualTo("price desc.min"); }
@Test public void canAccessScopedPriceDiscounted() throws Exception { assertThat(FACET_MODEL.allVariants().scopedPriceDiscounted().allTerms().expression()).isEqualTo("variants.scopedPriceDiscounted"); assertThat(FILTER_MODEL.allVariants().scopedPriceDiscounted().is(true)).extracting(expression()).containsExactly("variants.scopedPriceDiscounted:true"); assertThat(SORT_MODEL.allVariants().scopedPriceDiscounted().asc().expression()).isEqualTo("variants.scopedPriceDiscounted asc"); }
@Test public void searchForAvailableQuantityRanges() { withProductOfStock(client(), 10, productWith10Items -> { withProductOfStock(client(), 5, productWith5Items -> { final RangeFacetExpression<ProductProjection> productProjectionRangeFacetExpression = ProductProjectionSearchModel.of() .facet().allVariants().availability().availableQuantity().onlyGreaterThanOrEqualTo(new BigDecimal(1)); final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith10Items.getId(), productWith5Items.getId()))) .plusQueryFilters(m -> m.allVariants().availability().availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(6))) .plusFacets(productProjectionRangeFacetExpression); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); assertThat(res.getResults().get(0).getId()) .as("finds only the product with the sufficient amount stocked") .isEqualTo(productWith10Items.getId()); final RangeFacetResult facetResult = res.getFacetResult(productProjectionRangeFacetExpression); assertThat(facetResult.getRanges().get(0).getMax()) .isEqualTo("10.0"); }); }); }); }
@Test public void onNumberRangedSetAttributes() throws Exception { testRangeStats(FACET.allVariants().attribute().ofNumberSet(ATTR_NAME_NUMBER_SET).onlyGreaterThanOrEqualTo(valueOf(0)), rangeStats -> { assertThat(rangeStats.getLowerEndpoint()).isEqualTo("0.0"); assertThat(rangeStats.getUpperEndpoint()).isEqualTo(null); assertThat(rangeStats.getCount()).isEqualTo(2L); assertThat(rangeStats.getMin()).isEqualTo("5.0"); assertThat(rangeStats.getMax()).isEqualTo("10.0"); assertThat(rangeStats.getSum()).isEqualTo("20.0"); assertThat(rangeStats.getMean()).isEqualTo(6.666666666666667D); }); }
@Test public void canAccessPriceCurrency() throws Exception { assertThat(FACET_MODEL.allVariants().price().currency().allTerms().expression()).isEqualTo("variants.price.currencyCode"); assertThat(FILTER_MODEL.allVariants().price().currency().is(currency("EUR"))).extracting(expression()).containsExactly("variants.price.currencyCode:\"EUR\""); }
@Test public void facetSearchByScopedPriceDiscounted() { withProductOfPrices(asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)), product1 -> { withProductOfPrices(asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)), product2 -> { withProductOfPrices(asList(PriceDraft.of(EURO_40), PriceDraft.of(EURO_25).withCountry(DE)), product3 -> { final ProductDiscountDraft productDiscountDraft1 = discountDraftOfAbsoluteValue(product1, EURO_5); withProductDiscount(client(), productDiscountDraft1, productDiscount1 -> { assertEventually(s -> { final TermFacetExpression<ProductProjection> facetExpression = ProductProjectionSearchModel.of() .facet().allVariants().scopedPriceDiscounted().allTerms(); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))) .withFacets(facetExpression); final PagedSearchResult<ProductProjection> results = client().executeBlocking(search); assertThat(results.getResults()).hasSize(3); final List<TermStats> termStats = results.getFacetResult(facetExpression).getTerms(); s.assertThat(termStats).containsOnly( TermStats.of(BOOL_TRUE, 1L), TermStats.of(BOOL_FALSE, 2L)); }); }); }); }); }); }
@Test public void searchForAvailableQuantityRangesInChannels() { withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 10, channel, productWith10Items -> { withProductOfStockAndChannel(client(), 5, channel, productWith5Items -> { final RangeFacetExpression<ProductProjection> facet = ProductProjectionSearchModel.of() .facet().allVariants().availability().channels().channelId(channel.getId()) .availableQuantity().onlyGreaterThanOrEqualTo(new BigDecimal(1)); final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith10Items.getId(), productWith5Items.getId()))) .plusQueryFilters(m -> m.allVariants().availability().channels().channelId(channel.getId()) .availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(6))) .plusFacets(facet); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); assertThat(res.getResults().get(0).getId()) .as("finds only the product with the sufficient amount stocked") .isEqualTo(productWith10Items.getId()); final RangeFacetResult facetResult = res.getFacetResult(facet); assertThat(facetResult.getRanges().get(0).getMax()) .isEqualTo("10.0"); }); }); }); }); }
@Test public void onTimeRangedSetAttributes() throws Exception { testRangeStats(FACET.allVariants().attribute().ofTimeSet(ATTR_NAME_TIME_SET).onlyGreaterThanOrEqualTo(TIME_22H), rangeStats -> { assertThat(rangeStats.getLowerEndpoint()).isEqualTo("7.9509203E7"); assertThat(rangeStats.getUpperEndpoint()).isEqualTo(null); assertThat(rangeStats.getCount()).isEqualTo(2L); assertThat(rangeStats.getMin()).isEqualTo("7.9509203E7"); assertThat(rangeStats.getMax()).isEqualTo("8.3170204E7"); assertThat(rangeStats.getSum()).isEqualTo("2.4218861E8"); assertThat(rangeStats.getMean()).isEqualTo(8.072953666666667E7D); }); }
public MoneyFacetSearchModel<ProductProjection> price() { return moneyFacetSearchModel("price"); }
public ProductVariantFacetSearchModel allVariants() { return new ProductVariantFacetSearchModel(this, "variants"); }
@Test public void responseContainsRangeFacetsForAttributes() throws Exception { final RangeFacetExpression<ProductProjection> facetExpr = PRODUCT_MODEL.allVariants().price().centAmount().onlyGreaterThanOrEqualTo(0L); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr); testResult(search, result -> assertThat(result.getFacetResult(facetExpr).getRanges().get(0).getCount()).isGreaterThan(0)); }
public TermFacetSearchModel<ProductProjection, Boolean> scopedPriceDiscounted() { return booleanSearchModel("scopedPriceDiscounted").faceted(); } }
@Test public void onDatetimeRangedSetAttributes() throws Exception { testRangeStats(FACET.allVariants().attribute().ofDateTimeSet(ATTR_NAME_DATE_TIME_SET).onlyGreaterThanOrEqualTo(DATE_TIME_2001_22H), rangeStats -> { assertThat(rangeStats.getLowerEndpoint()).isEqualTo("1.000245909203E12"); assertThat(rangeStats.getUpperEndpoint()).isEqualTo(null); assertThat(rangeStats.getCount()).isEqualTo(2L); assertThat(rangeStats.getMin()).isEqualTo("1.000245909203E12"); assertThat(rangeStats.getMax()).isEqualTo("1.034463970204E12"); assertThat(rangeStats.getSum()).isEqualTo("3.03495578861E12"); assertThat(rangeStats.getMean()).isEqualTo(1.0116519295366666E12D); }); }
public MoneyFacetSearchModel<ProductProjection> price() { return moneyFacetSearchModel("price"); }
public ProductVariantFacetSearchModel allVariants() { return new ProductVariantFacetSearchModel(this, "variants"); }
@Test public void searchRequestIsAsExpected() { final ProductProjectionSearch actual = ProductProjectionSearchBuilder.ofCurrent() .facets(m -> m.allVariants().price().centAmount().allRanges()) .queryFilters(m -> m.allVariants().price().centAmount().isGreaterThanOrEqualTo(4L)) .sort(m -> m.createdAt().asc()) .expansionPaths(m -> m.categories()) .build(); final ProductProjectionSearch expected = ProductProjectionSearch.ofCurrent() .withFacets(m -> m.allVariants().price().centAmount().allRanges()) .withQueryFilters(m -> m.allVariants().price().centAmount().isGreaterThanOrEqualTo(4L)) .withSort(m -> m.createdAt().asc()) .withExpansionPaths(m -> m.categories()); assertThat(actual).isEqualTo(expected); } }