-1

I am using Sitecore 9.0.1 with SXA 1.7 .I have overriden the ContentPredicate() method for chinese language search box drawback from Sitecore.XA.Foundation.Search.Services.SearchService and i want to apply a patch for it so i have created config file under App_Config/Include folder but this patch is not working.

If i directly edit the Sitecore.XA.Foundation.Search the overriden method is getting called and its working but when i try to apply a patch it is not.

Sitecore.XA.Foundation.Search file:

<register serviceType="Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search" implementationType="Sitecore.XA.Foundation.Search.Services.SearchService, Sitecore.XA.Foundation.Search" lifetime="Singleton"/>
           <!-- <register serviceType="Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search" implementationType="SearchFeatureCustomization.CustomSearchService, SearchFeatureCustomization" lifetime="Singleton"/>-->
            

Here is my overriden code:

namespace SearchFeatureCustomization
{
    public class CustomSearchService : Sitecore.XA.Foundation.Search.Services.SearchService
    {
        protected override Expression<Func<ContentPage, bool>> ContentPredicate(string content)
        {
            Expression<Func<ContentPage, bool>> expression = PredicateBuilder.True<ContentPage>();
            if (string.IsNullOrWhiteSpace(content))
            {
                return expression;
            }
            foreach (string item in content.Split().TrimAndRemoveEmpty())
            {
                string t = item;
                expression = expression.And((ContentPage i) => i.AggregatedContent.Contains(t) || i.AggregatedContent.Equals(t, StringComparison.InvariantCultureIgnoreCase));
            }
            return expression;
        }
    }
}

This is my patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <services>

      <pipelines>
        <initialize>
          <register type="SearchFeatureCustomization.CustomSearchService, SearchFeatureCustomization"
                     patch:before="processor[@type='Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search']" lifetime="Singleton" resolve="true"/>
        </initialize>
      </pipelines>
    
   </services>
  </sitecore>
</configuration>

can anyone please help where i am going wrong.

Thanks

1
  • Placed you patch file under zzz folder in App_config as well Apr 15 at 10:09
2

Try this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore>
    <services>
      <register serviceType="Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search" implementationType="Sitecore.XA.Foundation.Search.Services.SearchService, Sitecore.XA.Foundation.Search" lifetime="Singleton">
        <patch:attribute name="implementationType">SearchFeatureCustomization.CustomSearchService, SearchFeatureCustomization</patch:attribute>
    </register>
    </services>
  </sitecore>
</configuration>
5
  • this is giving the error as "Could not load type 'SearchFeatureCustomization.iCustomSearchService' from assembly 'SearchFeatureCustomization'." because i dont have icustomsearchservice implemented @Gatogordo
    – Vinaya
    Apr 15 at 11:49
  • Sorry, typo with copy/paste and such.. updated and should be better now.
    – Gatogordo
    Apr 15 at 11:55
  • i added this but this patch is not calling the overridden method
    – Vinaya
    Apr 15 at 12:10
  • Updated once more to have an actual instead patch.. that should do it. Sorry for the mix-ups.. multitasking is not a good idea ;)
    – Gatogordo
    Apr 15 at 12:21
  • @Vinaya you're walking a fine line between raising a legitimate question about how config patching works, and asking the community to do your work for you. Stay on the right side of the line, please.
    – Mark Cassidy
    Apr 15 at 12:24
0

Create a patch like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore>
    <services>
    <register serviceType="SearchFeatureCustomization.iCustomSearchService, SearchFeatureCustomization" implementationType="SearchFeatureCustomization.CustomSearchService, SearchFeatureCustomization" lifetime="Singleton" patch:before="register[@serviceType='Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search']"/>
    </services>
  </sitecore>
</configuration>
2
  • @Gatogordo i dont have icustomSearchService implementation
    – Vinaya
    Apr 15 at 10:31
  • I'll add my own answer - will be easier than editing this one which has the correct intention but some things missing as well.
    – Gatogordo
    Apr 15 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.