The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
By default, when you create Search indexes in Sitefinity, you cannot specify the pages to which the search index applies. Sitefinity indexes the content of all pages. However, in some specific use case scenarios you may need to have search indexes that apply to different groups of pages. For example, you may need to have a search index which indexes the content under a specific group page and to have another search index which indexes the content under another group page. Moreover, you may also want to preserve the default functionality and to be able to create global search indexes as well.
The easiest way to achieve this functionality is to extend the default page inbound pipe and to add your custom logic there.
The first steps will be to create a custom page inbound pipe which inherits from the default PageIndoundPipe class in the following way:
In the PageInboundPipeCustom.cs class, you need to override the PushData() method. Inside this method you can get the name of the search index from the publishing point as shown in the code sample below:
and depending on the name of the search index specified under Administration -> Search indexes
we can get the pages under the group page that we would like this search indexed to be applied to and pass these pages to the base PushData() method.
Here is a sample implementation of the PushData() method where we have specified that the Search index 1 will be applied to pages created under Group page 1 while Search index 2 will index the pages under Group page 2:
In order to allow the global search indexes to function as expected we need to add a condition inside the PushData() method (in the very beginning of the method before our custom logic) so that when the name of the search index is not equal to the specified search indexes to pass all the pages to the base.PushData() method and this way to include all the pages in the internal search when using the rest of the search indexes. Here is also a sample code:
After performing the above please build the solution, restart the application and re-index the search indexes from Administration -> Search indexes -> <Your Search index> -> Actions link -> Reindex. Then you will be able to test the custom functionality for the search indexes.
The PageInboundPipeCustom.cs and the Global.asax files are available on GitHub.
Here is a video of the end result:
Sabrie Nedzhip is a Tech Support Engineer at Telerik. She joined the Sitefinity Support team in December 2013.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
You have the right to request deletion of your Personal Information at any time.
You can also ask us not to pass your Personal Information to third parties here: Do Not Sell My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.Learn More