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 implementation- SearchService- Search service is responsible of obtaining Feed data & product data from OCAPI. It later uses provided - ISearchHitListMergerto merge data from both sources.
- ISearchRequestCreatorwith implementation- SearchRequestCreator- SearchRequestCreator is used to convert - IQueryCollectioninto- SfccSearchParametersthat will be used to make requests to OCAPI. Query parameters that are taken into account are:- q, query, count, skip, categories, sort, minPrice, maxPrice
- ISearchHitListMergerwith implementation- SearchHitListMergermerges lists of Poq.Products with list of SfccProductSearchHit
- ISearchHitMergerwith implementation- SearchHitMergermerges Poq.Product and SfccProductSearchHit
- ICustomDataMergerwith implementation- CustomDataMergeris responsible of merging- Poq.Contract.SearchResponseProductListing.CustomDatawith information provided in SfccProduct.
- IFormsMergerwith implementation- FormsMergeris responsible of merging- Poq.Contract.SearchResponseProductListing.Formswith information provided by SfccProduct.
- IPriceMergerwith implementation- PriceMergermerges- Poq.Contract.SearchResponseProductListing.Priceswith information provided by SfccProduct.
- IPromotionsMergerwith implementation- PromotionsMergermerges- Poq.Contract.SearchResponseProductListing.Promotionswith SfccProduct promotions information.
- IReviewsMergerwith implementation- ReviewsMergerpromotions information in Poq.Product as- Poq.Contract.SearchResponseProductListing.Reviews.
- IVariantsMergerwith implementation- VariantsMergermerges 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.