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:
ISearchService
with implementationSearchService
Search service is responsible of obtaining Feed data & product data from OCAPI. It later uses provided
ISearchHitListMerger
to merge data from both sources.ISearchRequestCreator
with implementationSearchRequestCreator
SearchRequestCreator is used to convert
IQueryCollection
intoSfccSearchParameters
that will be used to make requests to OCAPI. Query parameters that are taken into account are:q, query, count, skip, categories, sort, minPrice, maxPrice
ISearchHitListMerger
with implementationSearchHitListMerger
merges lists of Poq.Products with list of SfccProductSearchHitISearchHitMerger
with implementationSearchHitMerger
merges Poq.Product and SfccProductSearchHitICustomDataMerger
with implementationCustomDataMerger
is responsible of mergingPoq.Contract.SearchResponseProductListing.CustomData
with information provided in SfccProduct.IFormsMerger
with implementationFormsMerger
is responsible of mergingPoq.Contract.SearchResponseProductListing.Forms
with information provided by SfccProduct.IPriceMerger
with implementationPriceMerger
mergesPoq.Contract.SearchResponseProductListing.Prices
with information provided by SfccProduct.IPromotionsMerger
with implementationPromotionsMerger
mergesPoq.Contract.SearchResponseProductListing.Promotions
with SfccProduct promotions information.IReviewsMerger
with implementationReviewsMerger
promotions information in Poq.Product asPoq.Contract.SearchResponseProductListing.Reviews
.IVariantsMerger
with implementationVariantsMerger
merges 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.