January 12, 2009

Sitefinity: Clean Up Search Results

Problem:

You are using Sitefinity 3.x and your page templates and other non-desirable parts of the pages are showing up in search results.

Reason:

Sitefinity spiders your site instead of searching the data. For the most part, this is a good thing, but it pollutes your search data.

Workaround:

Sitefinity gives us the tools to hide the template from the search spider, but they are rather hidden. To use this workaround, I am going to work under the assumption that all of your templates have a standardized naming scheme for their ContentPlaceHolder objects. For example, all of my pages have the main content in a ContentPlaceHolder named "Content," my sidebar is in a ContentPlaceHolder named "SideBarContent," and so on.

First, create a new master page that is empty except for the ContentPlaceHolder objects you want included in the search results and the header tag ContentPlaceHolder. Since I only want what is in my primary content area to appear in the search results, I have one ContentPlaceHolder in my body named "Content." Upload this into Sitefinity.

Second, if you do not have an App_Code folder in your Sitefinity project, add one to the project root.

Third, create a BasePage class. This class will inherit from InternalPage. Override the OnPreInit() function and drop in the following code...


base.OnPreInit(e);
if (CmsContext.IsCrawlerRequest)
{
this.MasterPageFile = "~/App_Master/SearchOverrideMasterPage.master";
}


...where SearchOverrideMasterPage.master is the name of the new master page you want to uploaded in step one.

Fourth, go into the Sitefinity folder and edit cmsentrypoint.aspx. Change...
Inherits="Telerik.Cms.Web.InternalPage"
...to be...
Inherits="ClassNameOfBaseClass"
...where ClassNameOfBaseClass is the name of the class you created in Step 3.

Fifth, go into your App_Data/Search folder and delete the folders contained therein to delete the current search indices and results.

Finally, go into Sitefinity's Administration tab and under Services / Search, click "Start indexing" under each search index.

1 comment:

Unknown said...

Excellent workaround! Thanks!