How to extend the search in Relate+ 2.0 for showing CMS-pages..
As many of you might now I left EPiServer two weeks ago for a new adventure at Logica… But before I left I was working a lot with a project about migration from Relate+ to Relate+ 2.0, http://world.episerver.com/Articles/Items/Migrate-EPiServer-Relate-1-to-EPiServer-Relate-2/. If you start a new project you will soon find out that there are no search for ordinary cms content. Even though Relate+ 2.0 have search for all community content, and cms-pages as well.
So on EPiCenter, EPiServer’s own intranet, they had a lot of pages that needed to be found. So what I needed to do was to extend the existing functionality with a little bit more code.
We need to create a new menuitem on the searchpage.
Add a new usercontrol to our project for rendering the result.
Add some logic to extend the search so it will handle cms-pages as well.
Create a new usercontrol:
So we add a new usercontrol in the SearchControls folder:
The important part of this code is the method protected override string GetDesc(object dataItem), this will get some of the text indexed on the specific page in the property mainbody. You could make some changes so that it will take all text that is index on the specific page by changing this:
if (responseItem.ItemType == typeof(EPiServer.Core.PageData).GetSearchFieldItemType())
string seachitem = responseItem.Id;
string myguid = seachitem.Substring(0, 36);
var pageguid = new Guid(myguid);
PermanentPageLinkMap map = PermanentLinkMapStore.Find(pageguid) as PermanentPageLinkMap;
Now I need to get the result for pages and to do that we need to do some changes in SearchResult.aspx. Ee need to create a new method called LoadPageResult() and use that in the Onload method on SearchResult.aspx.
The LoadPageResult()-method should now use our usercontrol that we created earlier, something like this:
and the changes to OnLoad should end up something like this:
// Call base
Finally we need to add the LoadPageResult() to LoadAllKindOfElementResult(), method for rendering all searchcategories, as well. Otherwise pages will not show unless the visitor clicks on the menu item for showing pages. This method can be found in SearchResult.aspx.cs.
Well I think thats about it and now we have extended the Relate+ 2.0 templates so that it uses the index for ordinary cmspages as well
If you are experience any problems getting the indexed results, you will need to check the adress of the indexingservice. I made changes to the default installation so that the site could be found on localhost:17000 and therfore I had to change the indexingservice as well to use the same adress, otherwise it uses the computername instead of localhost by default.
You can also download the migration tool, and use the reindex tool included in that package to get a new index.