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 :)
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..
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):
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)
.InField(x => ((CustomProduct)x).GetProductCode())
.InField(x => ((CustomProduct)x).GetSupplierPart());
/// Change to be first search provider (otherwise other instances might be selected first)
public new int SortOrder => 1;
Again, hope this helps someone :)
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!
I have implemented a custom EnterpriseCatalogSearchProvider like this:
Which I have registered in StructureMap like this:
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:
And here's the request URL that doesn't return expected results:
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..