public ProductProjectionSortSearchModel sort() { return new ProductProjectionSortSearchModel(null, null); }
public SingleValueSortSearchModel<ProductProjection> score() { return searchModel("score").sorted(); } }
@Test public void onSku() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().sku().asc(), ids -> assertThat(ids).containsExactly(product1.getId(), product2.getId())); } @Test
@Test public void sortByMultipleAttributes() throws Exception { final ProductProjectionSearch singleSortedRequest = ProductProjectionSearch.ofStaged() .plusSort(productModel -> productModel.allVariants().attribute().ofString(ATTR_NAME_COLOR).asc()); final ProductProjectionSearch searchWithNameAsc = singleSortedRequest .plusSort(productModel -> productModel.name().locale(ENGLISH).asc()); testResultIds(searchWithNameAsc, resultIds -> assertThat(resultIds).containsExactly(product3.getId(), product1.getId(), product2.getId())); final ProductProjectionSearch searchWithNameDesc = singleSortedRequest .plusSort(productModel -> productModel.name().locale(ENGLISH).desc()); testResultIds(searchWithNameDesc, resultIds -> assertThat(resultIds).containsExactly(product1.getId(), product3.getId(), product2.getId())); }
@Test public void sortByLowestRating() { checkSorting( m -> m.reviewRatingStatistics().lowestRating().asc(), p -> assertThat(p.getReviewRatingStatistics().getLowestRating()).isEqualTo(LOWEST_RATING) ); }
@Test public void id() { final ProductProjectionSearch baseRequest = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().isIn(getAllIds())); final ProductProjectionSearch asc = baseRequest.withSort(m -> m.id().asc()); final ProductProjectionSearch desc = baseRequest.withSort(m -> m.id().desc()); assertEventually(() -> { final PagedSearchResult<ProductProjection> ascResult = client().executeBlocking(asc); assertThat(ascResult.getTotal()).isEqualTo(getAllIds().size()); final PagedSearchResult<ProductProjection> descResult = client().executeBlocking(desc); assertThat(descResult.getTotal()).isEqualTo(getAllIds().size()); final LinkedList<ProductProjection> reversedDesc = new LinkedList<>(descResult.getResults()); Collections.reverse(reversedDesc); assertThat(ascResult.getResults()).isEqualTo(reversedDesc); }); }
@Test public void score() { final ProductProjectionSearch baseRequest = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().isIn(getAllIds())); final ProductProjectionSearch asc = baseRequest.withSort(m -> m.score().asc()); assertEventually(() -> { final PagedSearchResult<ProductProjection> ascResult = client().executeBlocking(asc); assertThat(ascResult.getTotal()).isEqualTo(getAllIds().size()); }); }
@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())); }
private static List<ProductProjection> searchForCategoryAndSort(final String categoryId) { final ProductProjectionSearch searchRequest = ProductProjectionSearch.ofStaged() .withQueryFilters(productModel -> productModel.categories().id().is(categoryId)) .withSort(productModel -> productModel.categoryOrderHints().category(categoryId).asc()); return client().executeBlocking(searchRequest).getResults(); }
@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); } }
@Test public void onNumberAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofNumber(ATTR_NAME_NUMBER).desc(), ids -> assertThat(ids).containsExactly(product2.getId(), product1.getId())); }
@Test public void sortByCount() { checkSorting( m -> m.reviewRatingStatistics().count().desc(), p -> assertThat(p.getReviewRatingStatistics().getCount()).isEqualTo(REVIEWS_PER_PRODUCT) ); }
@Test public void onBooleanSetAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofBooleanSet(ATTR_NAME_BOOLEAN_SET).asc(), ids -> assertThat(ids).containsExactly(product1.getId(), product2.getId())); }
public ProductProjectionSortSearchModel sort() { return new ProductProjectionSortSearchModel(null, null); }
@Test public void sortByHighestRating() { checkSorting( m -> m.reviewRatingStatistics().highestRating().desc(), p -> assertThat(p.getReviewRatingStatistics().getHighestRating()).isEqualTo(HIGHEST_RATING) ); }
public SingleValueSortSearchModel<ProductProjection> score() { return searchModel("score").sorted(); } }
@Test public void onDateAttributes() throws Exception { testProductIds(PRODUCT_MODEL.allVariants().attribute().ofDate(ATTR_NAME_DATE).desc(), ids -> assertThat(ids).containsExactly(product2.getId(), product1.getId())); }
public ProductProjectionSortSearchModel sort() { return new ProductProjectionSortSearchModel(null, null); }
@Test public void searchForReviewsWithAverageRatingGreaterThan2() { final List<FacetRange<BigDecimal>> facetRanges = IntStream.range(LOWEST_RATING, HIGHEST_RATING) .mapToObj(i -> FacetRange.of(new BigDecimal(i), new BigDecimal(i + 1))) .collect(toList()); assertThat(facetRanges.toString()).isEqualTo("[[0 to 1), [1 to 2), [2 to 3), [3 to 4), [4 to 5)]"); final ProductProjectionSearch searchRequest = ProductProjectionSearch.ofStaged()//in prod it would be current .withResultFilters(m -> m.reviewRatingStatistics().averageRating().isGreaterThanOrEqualTo(new BigDecimal(2))) .withFacets(m -> m.reviewRatingStatistics().averageRating().onlyRange(facetRanges)) .withSort(m -> m.reviewRatingStatistics().averageRating().desc()); assertEventually(Duration.ofSeconds(60), Duration.ofMillis(100), () -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(searchRequest); assertThat(result.getResults()).hasSize(2); final ProductProjection productProjection = result.getResults().get(0); assertThat(productProjection.getReviewRatingStatistics().getCount()).isEqualTo(REVIEWS_PER_PRODUCT); final RangeFacetResult facetResult = (RangeFacetResult) result.getFacetResult("reviewRatingStatistics.averageRating"); assertThat(facetResult.getRanges().get(2)).isEqualTo(RangeStats.of("2.0", "3.0", 2L, null, "2.2", "2.7", "4.9", 2.45)); }); }
public SingleValueSortSearchModel<ProductProjection> id() { return searchModel("id").sorted(); }