1 min read
Search Service (aka PLP)
SearchService is found in Poq.Sfcc.Services namespace. It requires several dependencies to be used in your backend. All required dependencies could be registered with the provided IServiceCollection extension like in example below:
services.AddPoqSfccSearchServices();This will register the following services:
ISearchServicewith implementationSearchServiceSearch service is responsible of obtaining Feed data & product data from OCAPI. It later uses provided
ISearchHitListMergerto merge data from both sources.ISearchRequestCreatorwith implementationSearchRequestCreatorSearchRequestCreator is used to convert
IQueryCollectionintoSfccSearchParametersthat will be used to make requests to OCAPI. Query parameters that are taken into account are:q, query, count, skip, categories, sort, minPrice, maxPriceISearchHitListMergerwith implementationSearchHitListMergermerges lists of Poq.Products with list of SfccProductSearchHitISearchHitMergerwith implementationSearchHitMergermerges Poq.Product and SfccProductSearchHitICustomDataMergerwith implementationCustomDataMergeris responsible of mergingPoq.Contract.SearchResponseProductListing.CustomDatawith information provided in SfccProduct.IFormsMergerwith implementationFormsMergeris responsible of mergingPoq.Contract.SearchResponseProductListing.Formswith information provided by SfccProduct.IPriceMergerwith implementationPriceMergermergesPoq.Contract.SearchResponseProductListing.Priceswith information provided by SfccProduct.IPromotionsMergerwith implementationPromotionsMergermergesPoq.Contract.SearchResponseProductListing.Promotionswith SfccProduct promotions information.IReviewsMergerwith implementationReviewsMergerpromotions information in Poq.Product asPoq.Contract.SearchResponseProductListing.Reviews.IVariantsMergerwith implementationVariantsMergermerges Poq.Product.Variants with provided in SfccProduct information.
Here in an example of overriding default handling of Promotions. Promotions are not mapped by default on returned result, but that could be overridden if needed.
services.AddScoped<IPromotionsMerger, MyCustomPromotionsMerger>();public class MyCustomPromotionsMerger : IPromotionsMerger public SearchResponsePromotions? MergePromotions(Product poqProduct, SfccProductSearchHit sfccSearchHit) { return new SearchResponsePromotions(null, new List<string>() { "50% off" }); }When customizing the SearchService for your particular use case, take into consideration that the more interfaces you have to implement, the more complex your code will become. It may be preferable to introduce a completely bespoke implementation, rather than extensively customising the default behaviour.