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 implementation SearchService

    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 implementation SearchRequestCreator

    SearchRequestCreator is used to convert IQueryCollection into SfccSearchParameters 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 implementation SearchHitListMerger merges lists of Poq.Products with list of SfccProductSearchHit

  • ISearchHitMerger with implementation SearchHitMerger merges Poq.Product and SfccProductSearchHit

  • ICustomDataMerger with implementation CustomDataMerger is responsible of merging Poq.Contract.SearchResponseProductListing.CustomData with information provided in SfccProduct.

  • IFormsMerger with implementation FormsMerger is responsible of merging Poq.Contract.SearchResponseProductListing.Forms with information provided by SfccProduct.

  • IPriceMerger with implementation PriceMerger merges Poq.Contract.SearchResponseProductListing.Prices with information provided by SfccProduct.

  • IPromotionsMerger with implementation PromotionsMerger merges Poq.Contract.SearchResponseProductListing.Promotions with SfccProduct promotions information.

  • IReviewsMerger with implementation ReviewsMerger promotions information in Poq.Product as Poq.Contract.SearchResponseProductListing.Reviews.

  • IVariantsMerger with implementation VariantsMerger 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.