Set start page for search index?
How can I set a start page for a search index, like I could in 3.7? I want to search page content in a particular folder. There appears to be no way to do this when indexing static html content.
Hi,
There is no way to designate a start page from where the search will start, by default it indexes all pages.
This can be done by cusomizing the search pipe that pulls pages content to limit the search for only one under certain group page or parent page.
To create a search index that covers only a selection of pages, you can register a custom PagesInboundPipe, where you can set the range to be passed to this pipe. Then you can register the pipe in the search index creation template and it will appear as an additional option. Please find below detailed instruction how you can set this up.
1. Create a new class that inherits from the default PagesInboundPipe:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
Telerik.Sitefinity.Publishing.Pipes;
using
Telerik.Sitefinity.Modules.Pages;
using
Telerik.Sitefinity.Publishing;
using
Telerik.Sitefinity;
using
Telerik.Sitefinity.Publishing.Model;
using
Telerik.Sitefinity.Pages.Model;
namespace
SitefinityWebApp
public
class
PageInboundPipeCustom:PageInboundPipe
public
override
void
PushData(IList<Telerik.Sitefinity.Publishing.PublishingSystemEventInfo> items)
List<Telerik.Sitefinity.Publishing.PublishingSystemEventInfo> myItems =
new
List<Telerik.Sitefinity.Publishing.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);
if
(node.Page !=
null
&& node.Page.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
while
(
true
)
node = node.Parent;
if
(node.Title ==
"GroupPage"
)
//this will index only one page node with its children, don`t add items here for the pages that shouldn`t be indexed
myItems.Add(item);
break
;
if
(node.Parent ==
null
)
break
;
base
.PushData(myItems);
"GroupPage
" and then passing them to the base PushData() method, which will index only this selection of pages. You can customize this logic to include only the desired pages. Once you've build your custom InboundPipe for Pages, you'll neeed to register it in Global.asax, by subscribing to the Bootsrapper_Initialized event like this:void
Bootstrapper_Initialized(
object
sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
if
(e.CommandName ==
"Bootstrapped"
)
PublishingSystemFactory.RegisterPipe(PageInboundPipeCustom.PipeName,
typeof
(PageInboundPipeCustom));
var pipeSettings1 = PublishingSystemFactory.GetPipeSettings(PageInboundPipeCustom.PipeName);
PublishingSystemFactory.RegisterTemplatePipe(
"SearchItemTemplate"
, pipeSettings1);
protected
void
Application_Start(
object
sender, EventArgs e)
Bootstrapper.Initialized += Bootstrapper_Initialized;
void
Bootstrapper_Initialized(
object
sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
if
(e.CommandName ==
"Bootstrapped"
)
// UnregisterCustomPipes();
//you can unregister pipes if you want to make updates to a pipe installaiton or the pipe must be registered again
PipeFactory.UnregisterPipe(
"AirPipe"
);
PipeFactory.UnregisterPipe(
"PagePipe"
);
PipeFactory.UnregisterPipe(
"PagePipe1"
);
//installing pipes
PublishingSystemFactory.RegisterPipe(
"AirPipe"
,
typeof
(AirPipe));
var pipeSettings1 = PublishingSystemFactory.CreateDefaultPagePipeSettings(
"AirPipe"
);
pipeSettings1.UIName =
"AirPipe"
;
PublishingSystemFactory.RegisterPipeSettings(
"AirPipe"
, pipeSettings1);
var pipeDefinitions = PublishingSystemFactory.CreateDefaultPagePipeDefinitions();
PublishingSystemFactory.RegisterPipeDefinitions(
"AirPipe"
, pipeDefinitions);
var pipeMappings = PublishingSystemFactory.GetDefaultInboundMappingForPages();
PublishingSystemFactory.RegisterPipeMappings(
"AirPipe"
,
true
, pipeMappings);
pipeSettings1 = PublishingSystemFactory.GetPipeSettings(
"AirPipe"
);
PublishingSystemFactory.RegisterTemplatePipe(
"SearchItemTemplate"
, pipeSettings1);
//installing multiple instances of one Type of pipe is done like this:
// another pipe
PublishingSystemFactory.RegisterPipe(
"PagePipe"
,
typeof
(SolutionsPipe));
var pipeSettings2 = PublishingSystemFactory.CreateDefaultPagePipeSettings(
"PagePipe"
);
pipeSettings2.UIName =
"SolutionsPipe"
;
PublishingSystemFactory.RegisterPipeSettings(
"PagePipe"
, pipeSettings2);
var pipeDefinitions2 = PublishingSystemFactory.CreateDefaultPagePipeDefinitions();
PublishingSystemFactory.RegisterPipeDefinitions(
"PagePipe"
, pipeDefinitions2);
var pipeMappings2 = PublishingSystemFactory.GetDefaultInboundMappingForPages();
PublishingSystemFactory.RegisterPipeMappings(
"PagePipe"
,
true
, pipeMappings2);
pipeSettings2 = PublishingSystemFactory.GetPipeSettings(
"PagePipe"
);
PublishingSystemFactory.RegisterTemplatePipe(
"SearchItemTemplate"
, pipeSettings2);
//3-rd
PublishingSystemFactory.RegisterPipe(
"PagePipe1"
,
typeof
(VitavoxPipe));
var pipeSettings3 = PublishingSystemFactory.CreateDefaultPagePipeSettings(
"PagePipe1"
);
pipeSettings3.UIName =
"VitavoxPipe"
;
PublishingSystemFactory.RegisterPipeSettings(
"PagePipe1"
, pipeSettings3);
var pipeDefinitions3 = PublishingSystemFactory.CreateDefaultPagePipeDefinitions();
PublishingSystemFactory.RegisterPipeDefinitions(
"PagePipe1"
, pipeDefinitions3);
var pipeMappings3 = PublishingSystemFactory.GetDefaultInboundMappingForPages();
PublishingSystemFactory.RegisterPipeMappings(
"PagePipe1"
,
true
, pipeMappings3);
pipeSettings3 = PublishingSystemFactory.GetPipeSettings(
"PagePipe1"
);
PublishingSystemFactory.RegisterTemplatePipe(
"SearchItemTemplate"
, pipeSettings3);
Thank you for the extremely detailed response! I think this may do the trick.
I am trying out this method, however it is not working for me at all. It compiles, and i get no errors. However, It just doesn't do anything....
am i missing something?
I Made a thread about this myself, But still no reply. This is a task i need before my companies website can go live. any help would be appreciated. My source code is listed in the link..
Hi,
Make sure that after adding the required classes and register the custom pipe for pages to have a page titled GroupPage (as per the example provided before)
node = node.Parent;
if
(node.Title ==
"GroupPage"
)
//this will index only one page node with its children, don`t add items here for the pages that shouldn`t be indexed
are the node.Title's the same as the page name in the pages menu?
if i have a page called "About" the node should be "About" aswell right, But what if I have a space in the title.
"About Us" ,
Hi,
Yes the call to node.Title
(node.Title ==
"About us"
Daniel, just a though...
While it is detailed in the code sample it is worth re-iterating that registering the custom pipe MUST come in the Initialized event (and not the Initializing event which obviously occurs first - the correct event, Initialized, fires after the Search and Publishing modules are initialised/activated and having these modules operational is a pre-requisite to the correct lifecycle or operation of ones custom pipes when said pipes interact with the "SearchItemTemplate" and/or "PublishingItemTemplate" I believe?