Editor side panel search with custom EnterpriseCatalogSearchProvider

Vote:
 

I have implemented a custom EnterpriseCatalogSearchProvider like this:

public class CustomEnterpriseCatalogSearchProvider : EnterpriseCatalogSearchProvider
{
public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, IEnterpriseSettings enterpriseSettings, IContentTypeRepository contentTypeRepository)
: base(localizationService, enterpriseSettings, contentTypeRepository)
{
}

public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, IEnterpriseSettings enterpriseSettings, IContentTypeRepository contentTypeRepository, UIDescriptorRegistry uiDescriptorRegistry)
: base(localizationService, enterpriseSettings, contentTypeRepository, uiDescriptorRegistry)
{
}

public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, ISiteDefinitionResolver siteDefinitionResolver, IContentTypeRepository contentTypeRepository, UIDescriptorRegistry uiDescriptorRegistry)
: base(localizationService, siteDefinitionResolver, contentTypeRepository, uiDescriptorRegistry)
{
}

protected override IQueriedSearch AddContentSpecificFields(IQueriedSearch query)
{
return base.AddContentSpecificFields(query)
.InField(x => ((CustomProduct)x).GetProductCode())
.InField(x => ((CustomProduct)x).GetSupplierPart());
}
}

Which I have registered in StructureMap like this:

container.For().Use();

This works exactly as intended on the site custom search pages and also in the right hand catalog panel search in the Episerver Editor UI.

But the problem is the left hand content search panel in the Editor UI - it works in some environments but not in others (e.g. right now it works in our DXC Integration but not in Prep or Prod).

When I inspect the network requests, the difference is clear - here's the working XHR request URL:

https://integ.removedthedomain.co.nz/EPiServer/shell/Stores/searchresults/?parameters=%7B%22filterOnDeleted%22%3Atrue%7D&filterOnCulture=false&searchRoots=-1073741823__CatalogContent&providerId=MyProject_Features_Products_Search_Provider_CustomEnterpriseCatalogSearchProvider&searchQuery=AE490-003&dojo.preventCache=1534725304464

And here's the request URL that doesn't return expected results:

https://prep.removedthedomain.co.nz/EPiServer/shell/Stores/searchresults/?parameters=%7B%22filterOnDeleted%22%3Atrue%7D&filterOnCulture=false&searchRoots=-1073741823__CatalogContent&providerId=EPiServer_Find_Commerce_EnterpriseCatalogSearchProvider&searchQuery=AE490-003&dojo.preventCache=1534725317540

So it's clear that the providerId isn't being supplied with my configured CustomEnterpriseCatalogSearchProvider. I just can't understand why this would vary seemingly randomly between environments..

Epi versions:

EPiServer.CMS v11.9.3

EPiServer.CMS.UI v11.5.4

EPiServer.Commerce v11.8.5

EPiServer.Find v13.0.1

EPiServer.Find.Commerce v10.2.0

#196109
Aug 20, 2018 3:24
Vote:
 

Okay, from searching around some more I found the answer from this thread: https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2016/5/page-cms-search-not-replaceing-correctly/

It's simply that I needed to set a SortOrder number low enough to ensure my search provider would be used. Here's my code I added to my CustomEnterpriseCatalogSearchProvider to override the SortOrder:

public new int SortOrder => 1;

Hope this helps someone else :)

#196110
Aug 20, 2018 3:45
Vote:
 

Actually, I posted too soon - even with the SortOrder, it still seems to randomly use the default search provider.. I think I need to figure out either how to remove the default search provider or to figure out why it picks the other..

Any ideas?

#196111
Aug 20, 2018 4:24
Vote:
 

Okay, I was on the right track but had missed the key difference being that I needed to mark my CustomEnterpriseCatalogSearchProvider class as explicitly implementing ISortable. Full class that works now (no StructureMap config needed now due to SearchProvider attribute):

[SearchProvider]
public class CustomEnterpriseCatalogSearchProvider : EnterpriseCatalogSearchProvider, ISortable
{
public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, IEnterpriseSettings enterpriseSettings, IContentTypeRepository<ContentType> contentTypeRepository)
: base(localizationService, enterpriseSettings, contentTypeRepository)
{
}

public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, IEnterpriseSettings enterpriseSettings, IContentTypeRepository<ContentType> contentTypeRepository, UIDescriptorRegistry uiDescriptorRegistry)
: base(localizationService, enterpriseSettings, contentTypeRepository, uiDescriptorRegistry)
{
}

public CustomEnterpriseCatalogSearchProvider(LocalizationService localizationService, ISiteDefinitionResolver siteDefinitionResolver, IContentTypeRepository contentTypeRepository, UIDescriptorRegistry uiDescriptorRegistry)
: base(localizationService, siteDefinitionResolver, contentTypeRepository, uiDescriptorRegistry)
{
}

protected override IQueriedSearch<IContentData, QueryStringQuery> AddContentSpecificFields(IQueriedSearch<IContentData, QueryStringQuery> query)
{
return base.AddContentSpecificFields(query)
.InField(x => ((CustomProduct)x).GetProductCode())
.InField(x => ((CustomProduct)x).GetSupplierPart());
}

/// <summary>
/// Change to be first search provider (otherwise other instances might be selected first)
/// </summary>
public new int SortOrder => 1;
}

Again, hope this helps someone :)

#196123
Edited, Aug 20, 2018 6:54
Vote:
 

Oh, and I should mention how I diagnosed what was happening - use this code to observe the providers you have:

var searchProvidersManager = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Shell.Search.SearchProvidersManager>();

var providerPairs = searchProvidersManager.GetProviderPairs();

var enabledProviders = searchProvidersManager.GetEnabledProvidersByPriority("Commerce/Catalog", true);

In my case I was using the "Commerce/Catalog" view that was causing issues. The provider pairs gives you the full list but not in order which you can observe in each provider's settings which contains the SortOrder it picked up - this is how I realised mine wasn't getting my SortOrder of 1 that I posted about.

Again, hope this helps!

#196124
Edited, Aug 20, 2018 6:59
Vote:
 

You can also simply drag and drop the search providers here:

#196134
Aug 20, 2018 11:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.