November Happy Hour will be moved to Thursday December 5th.

Overriding SearchSubsection

Vote:
 

Hello.

So I have written code in my FindInitialization to override the SearchSubsection for a particular page. I have done this

  SearchClient.Instance.Conventions.ForInstancesOf<InfoPage>()
                .ExcludeField(x => x.SearchSubsection()) // remove the default mapping
                .IncludeField(x => x.SearchSubsection(true)); // add your own mapping
       public static string SearchSubsection<T>(this T page, bool overriding) where T : PageData
        {
            // we need to check if this page is a CategoryPage first
            if (page is InfoContainerPage)
            {
                return ""; // I assume nothing?
            }

            var loader = ServiceLocator.Current.GetInstance<IContentLoader>();
            var ancestors = loader.GetAncestors(page.ContentLink).OfType<InfoContainerPage>();
            if (ancestors.Any())
            {
                var closestCategoryPage = ancestors.Last();
                var pageName = closestCategoryPage.Name;
                var schoolCode = CommonHelper.GetSubstringByString("(", ")", pageName);
                return schoolCode;
            }
            // customs: nothing to declare
            return "";
        }

My code works when I rendex the whole content by using admin mode EPiServer Find Content Indexing Job  but when I edit the page or create a new one it doesn't uses by overridden function. Am I missing something?

#288735
Oct 06, 2022 9:10
Vote:
 

Check the index first

#288745
Oct 06, 2022 10:20
Vote:
 

Also did you add InfoPage to the UnifiedSearchRegistry?

#288746
Oct 06, 2022 10:21
Vote:
 

I do not understand, this works fine when I re-index the content but not when I create a new page in CMS.

#288753
Oct 06, 2022 12:27
Vote:
 

Hmm nothing comes to mind in terms of limitations with indexing through publish and using conventions...

You could try putting a breakpoint on your SearchSubsection code? Maybe look at the log files or indexing errors?

I know you can also configure a serializer to add your own logging to see if anythings up with a stack trace.

#288755
Oct 06, 2022 13:07
Vote:
 

As a thought, are you working in an environment with a shared database (e.g. one database used by a dev site and/or multiple developers working locally)? When you manually run a scheduled task on your local machine, that task will run on your local machine. If you publish a piece of content on your local machine, I'm not sure whether the indexing is guaranteed to happen on the same machine as the publish. I'm wondering whether, in your case, you've made changes to the indexing conventions on your local machine but someone else's instance is doing the indexing hence not reflecting your changes.

#288758
Oct 06, 2022 13:21
* 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.