Create a search index that applies to group of pages

By default, when you create search indexes in Sitefinity CMS, you cannot specify the pages to which the search index applies. Sitefinity CMS indexes the content of all pages. You can create a search index that applies only to a selection of pages under a group page by replacing the default PageInboundPipe with a custom one.

To achieve this, perform the following:

  1. Create a PageInboundPipeCustom.cs class, which inherits from the default PageInboundPipe class.
  2. In the PageInboundPipeCustom.cs class, override the PushData() method. With this method, you get the pages under the group page that you want to include in the internal search and pass them to the base PushData() method:
    C#
    using System.Collections.Generic;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Publishing;
    using Telerik.Sitefinity.Publishing.Pipes;
    
    namespace SitefinityWebApp
    {
        public class PageInboundPipeCustom : PageInboundPipe
        {
            public override void PushData(IList<PublishingSystemEventInfo> items)
            {
                List<PublishingSystemEventInfo> myItems = new List<PublishingSystemEventInfo>();
    
                foreach (var item in items)
                {
                    PageNode node = null;
    
                    if (item.Item is WrapperObject && ((WrapperObject)item.Item).WrappedObject != null)
                    {
                        node = (PageNode)((WrapperObject)item.Item).WrappedObject;
                    }
                    else
                    {
                        node = ((PageNode)item.Item);
                    }
                    
                    var pageData = node.GetPageData();
    
                    if (pageData != null && pageData.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
                    {
                        while (true)
                        {
                            node = node.Parent;
    
                            if (node.Title == "Group page name")
                            {
                                // this will index only one page node with its children
                                myItems.Add(item);
                                break;
                            }
    
                            if (node.Parent == null)
                            {
                                break;
                            }
                        }
                    }
                }
    
                // pass the pages under the selected group page to the base PushData() method
                base.PushData(myItems);
            }
        }
    }
  3. To replace the default PageInboundPipe with the custom one, you need to unregister the default pipe and register the custom one in your Global.asax file:
    C#
    using System;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Publishing;
    using Telerik.Sitefinity.Publishing.Pipes;
    
    namespace SitefinityWebApp
    {
        public class Global : System.Web.HttpApplication
        {
            protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
            }
    
            private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
            {
                PublishingSystemFactory.UnregisterPipe(PageInboundPipe.PipeName);
                PublishingSystemFactory.RegisterPipe(PageInboundPipeCustom.PipeName, typeof(PageInboundPipeCustom));
            }
        }
    }
  4. Build the solution and restart the application.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?