ProductProjectionSearchImpl(final ProductProjectionType productProjectionType){ super("/product-projections/search", ProductProjectionSearch.resultTypeReference(), ProductProjectionSearchModel.of().sort(), ProductProjectionSearchModel.of().filter(), ProductProjectionSearchModel.of().facet(), ProductProjectionExpansionModel.of(), ProductProjectionSearchImpl::new, additionalParametersOf(productProjectionType)); }
ProductProjectionSearchImpl(final ProductProjectionType productProjectionType){ super("/product-projections/search", ProductProjectionSearch.resultTypeReference(), ProductProjectionSearchModel.of().sort(), ProductProjectionSearchModel.of().filter(), ProductProjectionSearchModel.of().facet(), ProductProjectionExpansionModel.of(), ProductProjectionSearchImpl::new, additionalParametersOf(productProjectionType)); }
ProductProjectionSearchImpl(final ProductProjectionType productProjectionType){ super("/product-projections/search", ProductProjectionSearch.resultTypeReference(), ProductProjectionSearchModel.of().sort(), ProductProjectionSearchModel.of().filter(), ProductProjectionSearchModel.of().facet(), ProductProjectionExpansionModel.of(), ProductProjectionSearchImpl::new, additionalParametersOf(productProjectionType)); }
private MultiValueSortSearchModel<ProductProjection> sortModel() { return ProductProjectionSearchModel.of().sort().allVariants().attribute().ofString("size"); } }
@Test public void sortByCurrentScopedPrice() { final List<PriceDraft> prices1 = asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)); final List<PriceDraft> prices2 = asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)); final SortExpression<ProductProjection> sortExpression = ProductProjectionSearchModel.of().sort().allVariants().scopedPrice().currentValue().centAmount().asc(); sortCheck(prices1, prices2, sortExpression); }
@Test public void facetAndFilter() { final ReviewRatingStatisticsFacetedSearchSearchModel<ProductProjection> reviewRatingsModel = ProductProjectionSearchModel.of().facetedSearch().reviewRatingStatistics(); final TermFacetedSearchExpression<ProductProjection> count = reviewRatingsModel.count().is("20"); final TermFacetedSearchExpression<ProductProjection> averageRating = reviewRatingsModel.averageRating().is("2.7"); final TermFacetedSearchExpression<ProductProjection> highestRating = reviewRatingsModel.highestRating().is(String.valueOf(HIGHEST_RATING)); final TermFacetedSearchExpression<ProductProjection> lowestRating = reviewRatingsModel.lowestRating().is(String.valueOf(LOWEST_RATING)); final ProductProjectionSearch productProjectionSearch = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().is(product.getId())) .plusFacetedSearch(asList(count, averageRating, highestRating, lowestRating)); assertEventually(() -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(productProjectionSearch); final List<ProductProjection> productProjectionList = result.getResults(); assertThat(productProjectionList).isNotEmpty(); assertThat(productProjectionList.get(0).getId()).isEqualTo(product.getId()); assertThat(result.getFacetResult(count).getTotal()).as("count facet").isEqualTo(1L); assertThat(result.getFacetResult(averageRating).getTotal()).as("averageRating facet").isEqualTo(1L); assertThat(result.getFacetResult(highestRating).getTotal()).as("highestRating facet").isEqualTo(1L); assertThat(result.getFacetResult(lowestRating).getTotal()).as("lowestRating facet").isEqualTo(1L); }); }
@Test public void sortByValueScopedPrice() { final List<PriceDraft> prices1 = asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)); final List<PriceDraft> prices2 = asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)); final SortExpression<ProductProjection> sortExpression = ProductProjectionSearchModel.of().sort().allVariants().scopedPrice().value().centAmount().asc(); sortCheck(prices1, prices2, sortExpression); }
@Test public void facetedSearchExample() throws Exception { final ProductAttributeFacetedSearchSearchModel attributeModel = ProductProjectionSearchModel.of().facetedSearch().allVariants().attribute(); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacetedSearch(attributeModel.ofNumber(ATTR_NAME_SIZE).allTerms()) .plusFacetedSearch(attributeModel.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 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 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 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)); }); }); }); }); }); }