Package de.cxp.ocs.elasticsearch.prodset
Class HeroProductHandler
java.lang.Object
de.cxp.ocs.elasticsearch.prodset.HeroProductHandler
Hero products that should be displayed at the top of the result, come with
several uncomfortable requirements. This class helps to handle all of them:
- hero products should also be reflected by the facets, so follow up requests with filters should also remove non-matching hero products. Result counts and facet counts of course should reflect this behavior.
- hero products should also be under the control of result-pages. This is especially important if the page-size/result limit is lower than the amount of hero products!
- If several sets of hero products are defined, make sure the same product does not appear in more that one.
- Multiple hero product sets should return in the order as they have been requested
- Static product sets and dynamic product sets with sorting should return the single hits in the order they have been requested.
- Author:
- Rudolf Batt
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHeroProductHandler
(Map<SearchConfiguration.ProductSetType, ProductSetResolver> productSetResolvers) -
Method Summary
Modifier and TypeMethodDescriptionextractSlices
(org.elasticsearch.action.search.SearchResponse searchResponse, InternalSearchParams internalParams, SearchResult searchResult, VariantPickingStrategy variantPickingStrategy) Extract the hero products into separate ordered slices, that are attached to the searchResult.static Optional
<HeroProductsQuery> getHeroQuery
(InternalSearchParams internalParams) resolve
(ProductSet[] productSets, Searcher searcher, SearchContext searchContext) Resolve the given product sets into static product sets.
-
Field Details
-
QUERY_NAME_PREFIX
-
-
Constructor Details
-
HeroProductHandler
public HeroProductHandler(Map<SearchConfiguration.ProductSetType, ProductSetResolver> productSetResolvers)
-
-
Method Details
-
resolve
public StaticProductSet[] resolve(ProductSet[] productSets, Searcher searcher, SearchContext searchContext) Resolve the given product sets into static product sets. For given static product sets, the specified IDs are verified. For dynamic product sets, the matching IDs are fetched.- Parameters:
productSets
- array of product sets to be resolved to static product setssearcher
- matching Searcher instance for these productssearchContext
- context- Returns:
- array of resolved product sets
-
getHeroQuery
-
extractSlices
public static Set<String> extractSlices(org.elasticsearch.action.search.SearchResponse searchResponse, InternalSearchParams internalParams, SearchResult searchResult, VariantPickingStrategy variantPickingStrategy) Extract the hero products into separate ordered slices, that are attached to the searchResult.
In case the result was sorted or filtered, this method most likely won't extract slices anymore, because it expects them in the defined order at the top of the result.
- Parameters:
searchResponse
- ES search resultinternalParams
- with sortings and hero product-setssearchResult
- where hero product slices should be addedvariantPickingStrategy
- function to pick variant in case of inner variant hits- Returns:
- set of ids, that are already part of primary slices
-