Custom Search in Sitefinity 4.1.1574.0 Using Custom Pipes
Hi,
I want to update the Search Result template to display the Description from Page Title & Properties tinyurl.com/celydrf. If there is no Description set for the page only then display the description from Body Copy of the page.
More details of required functionality are given in points below
Hi Waqar,
Actually, adding the the Description field to the search result can be done by replacing the default PageInboundPipe with a custom one. What practically has to be done is to create a class in your project, that inherits from PageInboundPipe and override the SetWrapperObjectProperties method. In it we'll add the Description property of the page as a value for the Summary property of the wrapped object:
namespace
SitefinityWebApp
public
class
CustomInboundPipe : PageInboundPipe
protected
override
void
SetWrapperObjectProperties(Telerik.Sitefinity.Publishing.WrapperObject wrapperObject, Telerik.Sitefinity.Pages.Model.PageNode node)
base
.SetWrapperObjectProperties(wrapperObject, node);
if
(!wrapperObject.HasProperty(PublishingConstants.FieldSummary))
wrapperObject.AddProperty(PublishingConstants.FieldSummary, node.Page.Description.ToString());
Now, the default pipe should be replaced with a custom one in the Global.asax file of your project. On applicationStart we unregister the default pipe and register our custom pipe:
public
class
Global : System.Web.HttpApplication
protected
void
Application_Start(
object
sender, EventArgs e)
Bootstrapper.Initialized -= Bootstrapper_Initialized;
Bootstrapper.Initialized += Bootstrapper_Initialized;
void
Bootstrapper_Initialized(
object
sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
if
(args.CommandName ==
"Bootstrapped"
)
ReplacePagePipeWithCustomPagePipe();
private
void
ReplacePagePipeWithCustomPagePipe()
//Remove the default page pipe
PublishingSystemFactory.UnregisterPipe(PageInboundPipe.PipeName);
//This code will add the PagePipeNoIndex to the registered pipes with the original page pipe name
//so when the publishing system try's to use the page pipe will use the new one
PublishingSystemFactory.RegisterPipe(PageInboundPipe.PipeName,
typeof
(CustomInboundPipe));