public interface ProductProjectionSearch extends MetaModelSearchDsl<ProductProjection,ProductProjectionSearch,ProductProjectionSortSearchModel,ProductProjectionFilterSearchModel,ProductProjectionFacetSearchModel,ProductProjectionExpansionModel<ProductProjection>>, PriceSelectionRequestDsl<ProductProjectionSearch>, LocaleSelectionRequestDsl<ProductProjectionSearch>, StoreSelectionRequestDsl<ProductProjectionSearch>
MAX_OFFSET, MIN_OFFSET
Modifier and Type | Method and Description |
---|---|
default ProductProjectionSearch |
bySku(List<String> skus) |
default ProductProjectionSearch |
bySku(String sku) |
default ProductProjectionSearch |
bySlug(Locale locale,
String slug) |
PriceSelection |
getPriceSelection() |
Boolean |
isMarkingMatchingVariants() |
static ProductProjectionSearch |
of(ProductProjectionType productProjectionType)
Creates a search request object with the product projection type specified by
productProjectionType . |
static ProductProjectionSearch |
ofCurrent()
Creates a search request object for the current data of a product.
|
static ProductProjectionSearch |
ofStaged()
Creates a search request object for the staged data of a product.
|
ProductProjectionSearch |
plusExpansionPaths(ExpansionPath<ProductProjection> expansionPath)
Creates a new object with the properties of the old object but adds
expansionPath to the expansion paths. |
ProductProjectionSearch |
plusExpansionPaths(Function<ProductProjectionExpansionModel<ProductProjection>,ExpansionPathContainer<ProductProjection>> m)
Creates a new object with the properties of the old object but adds a new expansion path to it by using meta models.
|
ProductProjectionSearch |
plusExpansionPaths(List<ExpansionPath<ProductProjection>> expansionPaths)
Creates a new object with the properties of the old object but adds
expansionPaths to the expansion paths. |
ProductProjectionSearch |
plusFacetedSearch(FacetedSearchExpression<ProductProjection> facetedSearchExpression)
Returns a new object with the new faceted search expression appended to the existing faceted search (combination of the query parameter
facet
with the facet expression and the query parameters filter.facet and filter with the filter expressions). |
ProductProjectionSearch |
plusFacetedSearch(List<FacetedSearchExpression<ProductProjection>> facetedSearchExpressions)
Returns a ResourceSearch with the new faceted search expression list appended to the existing faceted search (combination of the query parameter
facet
with the facet expression and the query parameters filter.facet and filter with the filter expressions). |
ProductProjectionSearch |
plusFacetFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
Creates a new object with the properties of the old object but adds a new filter list to the
facetFilters by using meta models. |
ProductProjectionSearch |
plusFacetFilters(List<FilterExpression<ProductProjection>> filterExpressions)
Returns a new object with the new facet filter list appended to the existing facet filters (query parameter
filter.facet ). |
ProductProjectionSearch |
plusFacets(FacetExpression<ProductProjection> facetExpression)
Returns a new object with the new facet expression appended to the existing facets (query parameter
facet ). |
ProductProjectionSearch |
plusFacets(Function<ProductProjectionFacetSearchModel,FacetExpression<ProductProjection>> m)
Creates a new object with the properties of the old object but adds a new facet to it by using meta models.
|
ProductProjectionSearch |
plusFacets(List<FacetExpression<ProductProjection>> facetExpressions)
Returns a ResourceSearch with the new facet expression list appended to the existing facets (query parameter
facet ). |
ProductProjectionSearch |
plusLocaleSelection(LocaleSelection localeSelection) |
ProductProjectionSearch |
plusQueryFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
Creates a new object with the properties of the old object but adds a new filter list to the
queryFilters by using meta models. |
ProductProjectionSearch |
plusQueryFilters(List<FilterExpression<ProductProjection>> filterExpressions)
Returns a new object with the new query filter expression list appended to the existing query filters (query parameter
filter.query ). |
ProductProjectionSearch |
plusResultFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
Creates a new object with the properties of the old object but adds a new filter list to the
resultFilters by using meta models. |
ProductProjectionSearch |
plusResultFilters(List<FilterExpression<ProductProjection>> filterExpressions)
Returns a new object with the new result filter expression list appended to the existing result filters (query parameter
filter ). |
ProductProjectionSearch |
plusSort(Function<ProductProjectionSortSearchModel,SortExpression<ProductProjection>> m)
Creates a new object with the properties of the old object but adds a new sort expression to it by using meta models.
|
ProductProjectionSearch |
plusSort(List<SortExpression<ProductProjection>> sortExpressions)
Returns a new object with the new sort expression list appended to the existing sort expressions.
|
ProductProjectionSearch |
plusSort(SortExpression<ProductProjection> sortExpression)
Returns a new object with the new sort expression list appended to the existing sort expressions.
|
static com.fasterxml.jackson.core.type.TypeReference<PagedSearchResult<ProductProjection>> |
resultTypeReference()
Creates a container which contains the full Java type information to deserialize the query result (NOT this class) from JSON.
|
ProductProjectionSearch |
withExpansionPaths(ExpansionPath<ProductProjection> expansionPath)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath . |
ProductProjectionSearch |
withExpansionPaths(Function<ProductProjectionExpansionModel<ProductProjection>,ExpansionPathContainer<ProductProjection>> m)
Creates a new object with the properties of the old object but replaces all expansion paths with a single
expansionPath by using meta models. |
ProductProjectionSearch |
withExpansionPaths(List<ExpansionPath<ProductProjection>> expansionPaths)
Creates a new object with the properties of the old object but replaces all expansion paths with
expansionPaths . |
ProductProjectionSearch |
withFacetedSearch(FacetedSearchExpression<ProductProjection> facetedSearchExpression)
Returns a new object with the new faceted search expression as facets (combination of the query parameter
facet
with the facet expression and the query parameters filter.facet and filter with the filter expressions). |
ProductProjectionSearch |
withFacetedSearch(List<FacetedSearchExpression<ProductProjection>> facetedSearchExpressions)
Returns a new object with the new faceted search expression list as faceted search (combination of the query parameter
facet
with the facet expression and the query parameters filter.facet and filter with the filter expressions). |
ProductProjectionSearch |
withFacetFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
Creates a new object with the properties of the old object but replaces all filters with a list of filter expressions to the
facetFilters by using meta models. |
ProductProjectionSearch |
withFacetFilters(List<FilterExpression<ProductProjection>> filterExpressions)
Returns a new object with the new facet filter list as facet filter (query parameter
filter.facet ). |
ProductProjectionSearch |
withFacets(FacetExpression<ProductProjection> facetExpression)
Returns a new object with the new facet expression as facets (query parameter
facet ). |
ProductProjectionSearch |
withFacets(Function<ProductProjectionFacetSearchModel,FacetExpression<ProductProjection>> m)
Creates a new object with the properties of the old object but replaces all facets with a single facet expression to it by using meta models.
|
ProductProjectionSearch |
withFacets(List<FacetExpression<ProductProjection>> facets)
Returns a new object with the new facet expression list as facets (query parameter
facet ). |
ProductProjectionSearch |
withFuzzy(Boolean fuzzy)
Returns an ResourceSearch with modified fuzzy parameter.
|
ProductProjectionSearch |
withFuzzyLevel(Integer fuzzyLevel)
Returns an ResourceSearch with modified fuzzyLevel parameter.
|
ProductProjectionSearch |
withLimit(Long limit)
Returns a new object with the new limit.
|
ProductProjectionSearch |
withLocaleSelection(LocaleSelection localeSelection) |
ProductProjectionSearch |
withMarkingMatchingVariants(Boolean markMatchingVariants)
Flag to control if the
ProductVariant.isMatchingVariant() should be filled. |
ProductProjectionSearch |
withOffset(Long offset)
Returns a new object with the new offset.
|
ProductProjectionSearch |
withPriceSelection(PriceSelection priceSelection)
Uses the cart price selection logic to retrieve the prices for product variants.
|
ProductProjectionSearch |
withQueryFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
Creates a new object with the properties of the old object but replaces all filters with a list of filter expressions to the
queryFilters by using meta models. |
ProductProjectionSearch |
withQueryFilters(List<FilterExpression<ProductProjection>> filterExpressions)
Returns a new object with the new query filter expression list as query filters (query parameter
filter.query ). |
ProductProjectionSearch |
withResultFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
Creates a new object with the properties of the old object but replaces all filters with a list of filter expressions to the
resultFilters by using meta models. |
ProductProjectionSearch |
withResultFilters(List<FilterExpression<ProductProjection>> filterExpressions)
Returns a new object with the new result filter expression list as result filter (query parameter
filter ). |
ProductProjectionSearch |
withSort(Function<ProductProjectionSortSearchModel,SortExpression<ProductProjection>> m)
Creates a new object with the properties of the old object but replaces all sort expressions with a single sort expression to it by using meta models.
|
ProductProjectionSearch |
withSort(List<SortExpression<ProductProjection>> sortExpressions)
Returns a new object with the new sort expressions.
|
ProductProjectionSearch |
withSort(SortExpression<ProductProjection> sortExpression)
Returns a new object with the new sort expressions.
|
ProductProjectionSearch |
withStoreSelection(StoreSelection storeSelection) |
ProductProjectionSearch |
withText(Locale locale,
String text)
Returns a new object with the new text as search text.
|
ProductProjectionSearch |
withText(LocalizedStringEntry text)
Returns a new object with the new text as search text.
|
withAdditionalQueryParameter
withLimit, withOffset
endpoint, fuzzyLevel, isFuzzy, limit, offset, text
deserialize, toSearch
canDeserialize, httpRequestIntent
sort
facetFilters, queryFilters, resultFilters
facets
plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths
expansionPaths
facetedSearch
getLocaleSelection
getStoreSelection
static com.fasterxml.jackson.core.type.TypeReference<PagedSearchResult<ProductProjection>> resultTypeReference()
static ProductProjectionSearch ofStaged()
static ProductProjectionSearch ofCurrent()
static ProductProjectionSearch of(ProductProjectionType productProjectionType)
productProjectionType
.productProjectionType
- the desired projection type for the search resultsofStaged()
,
ofCurrent()
default ProductProjectionSearch bySlug(Locale locale, String slug)
default ProductProjectionSearch bySku(String sku)
default ProductProjectionSearch bySku(List<String> skus)
ProductProjectionSearch withText(LocalizedStringEntry text)
SearchDsl
withText
in interface SearchDsl<ProductProjection,ProductProjectionSearch>
text
- the new search text with locale, the locale should be enabled for the Project (see the project settings in the Merchant Center)text
ProductProjectionSearch withText(Locale locale, String text)
SearchDsl
withText
in interface SearchDsl<ProductProjection,ProductProjectionSearch>
locale
- the new locale, the locale should be enabled for the Project (see the project settings in the Merchant Center)text
- the new search texttext
ProductProjectionSearch withFuzzy(Boolean fuzzy)
SearchDsl
withFuzzy
in interface SearchDsl<ProductProjection,ProductProjectionSearch>
fuzzy
- a flag to indicate if fuzzy search is enabled (true) or not (false)ProductProjectionSearch withFuzzyLevel(Integer fuzzyLevel)
SearchDsl
final String searchWord = "abcdfgh"; final String productName = "abcdefgh"; withProduct(client(), builder -> builder.name(ofEnglish(productName)), product -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .withText(ENGLISH, searchWord) .withFuzzy(true); assertEventually(() -> { softAssert(s -> { s.assertThat(client().executeBlocking(request.withFuzzyLevel(0))) .as("level 0 matches not") .doesNotHave(product()); s.assertThat(client().executeBlocking(request.withFuzzyLevel(1))) .as("level 1 matches") .has(product()); s.assertThat(client().executeBlocking(request.withFuzzyLevel(2))) .as("level 2 matches") .has(product()); }); }); });
See the test code.
withFuzzyLevel
in interface SearchDsl<ProductProjection,ProductProjectionSearch>
fuzzyLevel
- defines level of unsharpness of the search using the Damerau-Levenshtein distanceProductProjectionSearch withFacets(List<FacetExpression<ProductProjection>> facets)
FacetDsl
facet
).withFacets
in interface FacetDsl<ProductProjection,ProductProjectionSearch>
facets
- the new facet expression listProductProjectionSearch plusFacets(Function<ProductProjectionFacetSearchModel,FacetExpression<ProductProjection>> m)
MetaModelFacetDsl
plusFacets
in interface MetaModelFacetDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFacetSearchModel>
m
- function to use the meta model for facets to create a facet expressionProductProjectionSearch plusResultFilters(List<FilterExpression<ProductProjection>> filterExpressions)
FilterDsl
filter
).plusResultFilters
in interface FilterDsl<ProductProjection,ProductProjectionSearch>
filterExpressions
- the new result filter expression listresultFilters
plus the new filterExpressions
.ProductProjectionSearch plusResultFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
MetaModelFilterDsl
resultFilters
by using meta models.plusResultFilters
in interface MetaModelFilterDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFilterSearchModel>
m
- function to use the meta model for filters to create a filter expressionProductProjectionSearch plusQueryFilters(List<FilterExpression<ProductProjection>> filterExpressions)
FilterDsl
filter.query
).plusQueryFilters
in interface FilterDsl<ProductProjection,ProductProjectionSearch>
filterExpressions
- the new query filter expression listqueryFilters
plus the new filterExpressions
.ProductProjectionSearch plusQueryFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
MetaModelFilterDsl
queryFilters
by using meta models.plusQueryFilters
in interface MetaModelFilterDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFilterSearchModel>
m
- function to use the meta model for filters to create a filter expressionProductProjectionSearch plusFacetFilters(List<FilterExpression<ProductProjection>> filterExpressions)
FilterDsl
filter.facet
).plusFacetFilters
in interface FilterDsl<ProductProjection,ProductProjectionSearch>
filterExpressions
- the new facet filter expression listfacetFilters
plus the new filterExpressions
.ProductProjectionSearch plusFacetFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
MetaModelFilterDsl
facetFilters
by using meta models.plusFacetFilters
in interface MetaModelFilterDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFilterSearchModel>
m
- function to use the meta model for filters to create a filter expressionProductProjectionSearch plusSort(List<SortExpression<ProductProjection>> sortExpressions)
SortDsl
plusSort
in interface SortDsl<ProductProjection,ProductProjectionSearch>
sortExpressions
- the new sort expression listsortExpressions
.ProductProjectionSearch plusSort(SortExpression<ProductProjection> sortExpression)
SortDsl
plusSort
in interface SortDsl<ProductProjection,ProductProjectionSearch>
sortExpression
- the new sort expressionsortExpressions
.ProductProjectionSearch plusSort(Function<ProductProjectionSortSearchModel,SortExpression<ProductProjection>> m)
MetaModelSortDsl
plusSort
in interface MetaModelSortDsl<ProductProjection,ProductProjectionSearch,ProductProjectionSortSearchModel>
m
- function to use the meta model for sort to create a sort expressionProductProjectionSearch withLimit(Long limit)
SearchDsl
withLimit
in interface SearchDsl<ProductProjection,ProductProjectionSearch>
limit
- the new limitlimit
ProductProjectionSearch withOffset(Long offset)
SearchDsl
withOffset
in interface SearchDsl<ProductProjection,ProductProjectionSearch>
offset
- the new offsetoffset
ProductProjectionSearch plusExpansionPaths(List<ExpansionPath<ProductProjection>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
to the expansion paths.plusExpansionPaths
in interface ReferenceExpansionDsl<ProductProjection,ProductProjectionSearch>
expansionPaths
- the new expansion paths to add to the existing onesProductProjectionSearch plusExpansionPaths(ExpansionPath<ProductProjection> expansionPath)
ReferenceExpansionDsl
expansionPath
to the expansion paths.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT); assertThat(fetch.expansionPaths()).isEmpty(); final ProductProjectionByIdGet fetch2 = fetch.plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged").isEmpty(); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2).isNotSameAs(fetch);
See the test code.
plusExpansionPaths
in interface ReferenceExpansionDsl<ProductProjection,ProductProjectionSearch>
expansionPath
- the new expansion path to add to the existing onesProductProjectionSearch plusFacetedSearch(FacetedSearchExpression<ProductProjection> facetedSearchExpression)
FacetedSearchDsl
facet
with the facet expression and the query parameters filter.facet
and filter
with the filter expressions).
This enables the behaviour of the faceted search as explained in the documentation.plusFacetedSearch
in interface FacetedSearchDsl<ProductProjection,ProductProjectionSearch>
facetedSearchExpression
- the new faceted search expressionProductProjectionSearch plusFacetedSearch(List<FacetedSearchExpression<ProductProjection>> facetedSearchExpressions)
FacetedSearchDsl
facet
with the facet expression and the query parameters filter.facet
and filter
with the filter expressions).
This enables the behaviour of the faceted search as explained in the documentation.plusFacetedSearch
in interface FacetedSearchDsl<ProductProjection,ProductProjectionSearch>
facetedSearchExpressions
- the new faceted search expression listProductProjectionSearch withFacetedSearch(FacetedSearchExpression<ProductProjection> facetedSearchExpression)
FacetedSearchDsl
facet
with the facet expression and the query parameters filter.facet
and filter
with the filter expressions).
This enables the behaviour of the faceted search as explained in the documentation.withFacetedSearch
in interface FacetedSearchDsl<ProductProjection,ProductProjectionSearch>
facetedSearchExpression
- the new faceted search expressionProductProjectionSearch withFacetedSearch(List<FacetedSearchExpression<ProductProjection>> facetedSearchExpressions)
FacetedSearchDsl
facet
with the facet expression and the query parameters filter.facet
and filter
with the filter expressions).
This enables the behaviour of the faceted search as explained in the documentation.withFacetedSearch
in interface FacetedSearchDsl<ProductProjection,ProductProjectionSearch>
facetedSearchExpressions
- the new faceted search expression listProductProjectionSearch withQueryFilters(List<FilterExpression<ProductProjection>> filterExpressions)
FilterDsl
filter.query
).withQueryFilters
in interface FilterDsl<ProductProjection,ProductProjectionSearch>
filterExpressions
- the new query filter expression listqueryFilters
as filterExpressions
ProductProjectionSearch withResultFilters(List<FilterExpression<ProductProjection>> filterExpressions)
FilterDsl
filter
).withResultFilters
in interface FilterDsl<ProductProjection,ProductProjectionSearch>
filterExpressions
- the new result filter expression listfilterExpressions
as resultFilters
ProductProjectionSearch plusExpansionPaths(Function<ProductProjectionExpansionModel<ProductProjection>,ExpansionPathContainer<ProductProjection>> m)
MetaModelReferenceExpansionDsl
An example in the product projection context:
final ProductProjectionByIdGet fetch1 = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(m -> m.categories()); assertThat(fetch1.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch1.plusExpansionPaths(m -> m.productType()); assertThat(fetch2.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"), ExpansionPath.of("productType"))) .isEqualTo(listOf(fetch1.expansionPaths(), ExpansionPath.of("productType"))); //this is equivalent to final ExpansionPath<ProductProjection> categoryExpand = ProductProjectionExpansionModel.of().categories().expansionPaths().get(0); final ExpansionPath<ProductProjection> productTypeExpand = ProductProjectionExpansionModel.of().productType().expansionPaths().get(0); final ProductProjectionByIdGet fetchB = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .withExpansionPaths(asList(categoryExpand, productTypeExpand)); assertThat(fetchB.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"), ExpansionPath.of("productType")));
See the test code.
plusExpansionPaths
in interface MetaModelReferenceExpansionDsl<ProductProjection,ProductProjectionSearch,ProductProjectionExpansionModel<ProductProjection>>
m
- function to use the meta model for expansions to create an expansion pathProductProjectionSearch withExpansionPaths(Function<ProductProjectionExpansionModel<ProductProjection>,ExpansionPathContainer<ProductProjection>> m)
MetaModelReferenceExpansionDsl
expansionPath
by using meta models.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .plusExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(m -> m.productType()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged") .isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType"))); assertThat(fetch2).isNotSameAs(fetch);
See the test code.
withExpansionPaths
in interface MetaModelReferenceExpansionDsl<ProductProjection,ProductProjectionSearch,ProductProjectionExpansionModel<ProductProjection>>
m
- function to use the meta model for expansions to create an expansion pathProductProjectionSearch withFacets(Function<ProductProjectionFacetSearchModel,FacetExpression<ProductProjection>> m)
MetaModelFacetDsl
withFacets
in interface MetaModelFacetDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFacetSearchModel>
m
- function to use the meta model for facets to create a facet expressionProductProjectionSearch withFacetFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
MetaModelFilterDsl
facetFilters
by using meta models.withFacetFilters
in interface MetaModelFilterDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFilterSearchModel>
m
- function to use the meta model for filters to create a list of filter expressionProductProjectionSearch withQueryFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
MetaModelFilterDsl
queryFilters
by using meta models.withQueryFilters
in interface MetaModelFilterDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFilterSearchModel>
m
- function to use the meta model for filters to create a list of filter expressionProductProjectionSearch withResultFilters(Function<ProductProjectionFilterSearchModel,List<FilterExpression<ProductProjection>>> m)
MetaModelFilterDsl
resultFilters
by using meta models.withResultFilters
in interface MetaModelFilterDsl<ProductProjection,ProductProjectionSearch,ProductProjectionFilterSearchModel>
m
- function to use the meta model for filters to create a list of filter expressionProductProjectionSearch plusFacets(FacetExpression<ProductProjection> facetExpression)
FacetDsl
facet
).plusFacets
in interface FacetDsl<ProductProjection,ProductProjectionSearch>
facetExpression
- the new facet expressionProductProjectionSearch plusFacets(List<FacetExpression<ProductProjection>> facetExpressions)
FacetDsl
facet
).plusFacets
in interface FacetDsl<ProductProjection,ProductProjectionSearch>
facetExpressions
- the new facet expression listProductProjectionSearch withFacets(FacetExpression<ProductProjection> facetExpression)
FacetDsl
facet
).withFacets
in interface FacetDsl<ProductProjection,ProductProjectionSearch>
facetExpression
- the new facet expressionProductProjectionSearch withSort(Function<ProductProjectionSortSearchModel,SortExpression<ProductProjection>> m)
MetaModelSortDsl
withSort
in interface MetaModelSortDsl<ProductProjection,ProductProjectionSearch,ProductProjectionSortSearchModel>
m
- function to use the meta model for sort to create a sort expressionProductProjectionSearch withFacetFilters(List<FilterExpression<ProductProjection>> filterExpressions)
FilterDsl
filter.facet
).withFacetFilters
in interface FilterDsl<ProductProjection,ProductProjectionSearch>
filterExpressions
- the new facet filter expression listfacetFilters
as filterExpressions
ProductProjectionSearch withExpansionPaths(ExpansionPath<ProductProjection> expansionPath)
ReferenceExpansionDsl
expansionPath
.
An example in the product projection context:
final ProductProjectionByIdGet fetch = ProductProjectionByIdGet.of("id", ProductProjectionType.CURRENT) .withExpansionPaths(ProductProjectionExpansionModel.of().categories()); assertThat(fetch.expansionPaths()) .isEqualTo(asList(ExpansionPath.of("categories[*]"))); final ProductProjectionByIdGet fetch2 = fetch.withExpansionPaths(ProductProjectionExpansionModel.of().productType()); assertThat(fetch.expansionPaths()).overridingErrorMessage("old object is unchanged") .isEqualTo(asList(ExpansionPath.of("categories[*]"))); assertThat(fetch2.expansionPaths()).isEqualTo(asList(ExpansionPath.of("productType"))); assertThat(fetch2).isNotSameAs(fetch);
See the test code.
This method also can be used to use the same expansions as in another request:
final ProductProjectionQuery query = ProductProjectionQuery.ofCurrent().withExpansionPaths(m -> m.categories()); final ProductProjectionSearch search = ProductProjectionSearch.ofCurrent().withExpansionPaths(query); assertThat(query.expansionPaths()) .hasSize(1) .as("reuse expansion spec from other request") .isEqualTo(search.expansionPaths());
See the test code.
withExpansionPaths
in interface ReferenceExpansionDsl<ProductProjection,ProductProjectionSearch>
expansionPath
- the new expansion pathsProductProjectionSearch withExpansionPaths(List<ExpansionPath<ProductProjection>> expansionPaths)
ReferenceExpansionDsl
expansionPaths
.withExpansionPaths
in interface ReferenceExpansionDsl<ProductProjection,ProductProjectionSearch>
expansionPaths
- the new expansion pathsProductProjectionSearch withSort(SortExpression<ProductProjection> sortExpression)
SortDsl
withSort
in interface SortDsl<ProductProjection,ProductProjectionSearch>
sortExpression
- the new sort expression listsortExpressions
ProductProjectionSearch withSort(List<SortExpression<ProductProjection>> sortExpressions)
SortDsl
withSort
in interface SortDsl<ProductProjection,ProductProjectionSearch>
sortExpressions
- the new sort expression listsortExpressions
ProductProjectionSearch withPriceSelection(@Nullable PriceSelection priceSelection)
Example for selecting just a currency
final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjectionSearch searchRequest = ProductProjectionSearch.ofStaged() .withQueryFilters(m -> m.id().is(product.getId()))//to limit the test scope .withPriceSelection(PriceSelection.of(EUR));//price selection config assertEventually(() -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(searchRequest); assertThat(result.getCount()).isEqualTo(1); final ProductVariant masterVariant = result.getResults().get(0).getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); });
See the test code.
Examples for different scenarios
withResources((CustomerGroup b2c) -> (CustomerGroup b2b) -> (Channel channel) -> { final PriceDraftDsl simplePriceInEuro = PriceDraft.of(EURO_30); final PriceDraftDsl priceWithCountry = PriceDraft.of(EURO_40).withCountry(CountryCode.AU); final PriceDraftDsl b2bPrice = PriceDraft.of(EURO_10).withCustomerGroup(b2b); final PriceDraftDsl priceWithChannel = PriceDraft.of(EURO_20).withChannel(channel); final PriceDraftDsl priceAll = PriceDraft.of(EURO_5) .withChannel(channel) .withCustomerGroup(b2c) .withCountry(DE); final List<PriceDraft> prices = asList(simplePriceInEuro, priceWithCountry, b2bPrice, priceWithChannel, priceAll); withProductOfPrices(prices, product -> { assertEventually(() -> { assertThat(searchWith(product, PriceSelection.of(EUR))).has(price(simplePriceInEuro)); assertThat(searchWith(product, PriceSelection.of(USD))).isNull(); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.AU))) .has(price(priceWithCountry)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(DE))) .as("if the country is not present it falls back to the price without country") .has(price(simplePriceInEuro)); final String aChannelId = "4698af68-fa24-49ab-8a3e-abb113d72c0a"; assertThat(searchWith(product, PriceSelection.of(EUR).withPriceChannelId(aChannelId))) .as("if a price with the channel is not present it falls back to the price without channel") .has(price(simplePriceInEuro)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceChannel(channel))) .has(price(priceWithChannel)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCustomerGroup(b2b))) .has(price(b2bPrice)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCustomerGroup(b2c))) .as("if a customer group does not have a special price the default price is used") .has(price(simplePriceInEuro)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.DE) .withPriceChannel(channel).withPriceCustomerGroup(b2c))) .has(price(priceAll)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.AU) .withPriceChannel(channel).withPriceCustomerGroup(b2c))) .as("channel wins over country and customer group") .has(price(priceWithChannel)); assertThat(searchWith(product, PriceSelection.of(EUR).withPriceCountry(CountryCode.AU).withPriceCustomerGroup(b2c))) .as("country wins over customer group") .has(price(priceWithCountry)); }); }); });
See the test code.
withPriceSelection
in interface PriceSelectionRequestDsl<ProductProjectionSearch>
priceSelection
- parameters for the price selection, using null deletes the valuesProductVariant.getPrice()
ProductProjectionSearch withMarkingMatchingVariants(Boolean markMatchingVariants)
ProductVariant.isMatchingVariant()
should be filled.
If markMatchingVariants parameter is true those ProductVariants that match the search query have the additional field isMatchingVariant set to true. For the other variants in the same product projection this field is set to false.
If markMatchingVariants parameter is false the ProductVariants do not contain the field isMatchingVariant.markMatchingVariants
- flag to populate the ProductVariant.isMatchingVariant()
fieldfinal String attributeName = randomKey(); withProductType(client(), () -> productTypeDraft(attributeName), productType -> { final List<ProductVariantDraft> allVariants = Stream.of("1", "2", "3", "4") .map(s -> ProductVariantDraftBuilder.of().attributes(AttributeDraft.of(attributeName, s)).build()) .collect(Collectors.toList()); final ProductDraftBuilder productDraftBuilder = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), allVariants); withProduct(client(), productDraftBuilder, product -> { final ProductProjectionSearch searchRequest = ProductProjectionSearch.ofStaged() .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(); assertThat(productProjectionOptional).isPresent(); final ProductProjection productProjection = productProjectionOptional.get(); assertThat(productProjection.getMasterVariant().isMatchingVariant()).isFalse(); final ProductVariant variantWithAttribute2 = productProjection.getVariants().get(0); assertThat(variantWithAttribute2.isMatchingVariant()).isFalse(); final ProductVariant positiveVariant = productProjection.getVariants().get(1); assertThat(positiveVariant.getAttribute(attributeName).getValueAsString()).isEqualTo("3"); assertThat(positiveVariant.isMatchingVariant()).isTrue(); }); assertEventually(() -> { final ProductProjectionSearch withoutFlagSearchRequest = searchRequest.withMarkingMatchingVariants(false); final Optional<ProductProjection> productProjectionOptional = client().executeBlocking(withoutFlagSearchRequest).head(); assertThat(productProjectionOptional).isPresent(); assertThat(productProjectionOptional.get().getMasterVariant().isMatchingVariant()).isNull(); assertThat(productProjectionOptional.get().getVariants().get(0).isMatchingVariant()).isNull(); final ProductVariant positiveVariant = productProjectionOptional.get().getVariants().get(1); assertThat(positiveVariant.getAttribute(attributeName).getValueAsString()).isEqualTo("3"); assertThat(positiveVariant.isMatchingVariant()).isNull(); }); }); });
See the test code.
ProductProjectionSearch withLocaleSelection(@Nullable LocaleSelection localeSelection)
withLocaleSelection
in interface LocaleSelectionRequestDsl<ProductProjectionSearch>
ProductProjectionSearch plusLocaleSelection(@Nullable LocaleSelection localeSelection)
ProductProjectionSearch withStoreSelection(@Nullable StoreSelection storeSelection)
withStoreSelection
in interface StoreSelectionRequestDsl<ProductProjectionSearch>
@Nullable PriceSelection getPriceSelection()
getPriceSelection
in interface PriceSelectionRequestDsl<ProductProjectionSearch>