Wednesday, 4 July 2012

Customising Search result page through Feature

To customize your search result page, you need to follow below steps; at the end you will end up a .wsp solution that will be used for deployment to deploy your customization to various environments.
I am assuming that you have search centre site. Browse your search result page and modify web parts and supply your changes. For instance in “Search Box” web part you can specify the search result page.
Similarly in “Search core result” webpart you can specify your xsl for the custom layout for the results and if you want additional columns you can specify there as well.

Specify the xsl location not xsl itself. We will be deploying that xsl in _layouts/Masood/demo/customsearchresults.xsl through SharePoint 2010 project as show below.
Once you have done your modifications, it’s time to export those modifications to xml as shown below image:
Perform expert to only modified web parts. For instance we modified “Search Box” and “Search Core Results” web part and save those files.
Now create a SharePoint 2010 project.
Browse 14\TEMPLATE\SiteTemplates\SRCHCEN\XML and open xml file in notepad


and search for “<File Url="results.aspx" Type="GhostableInLibrary">”
Copy the contents of above node and paste it your Elements file of “SearchPage” module as show below:

Now open SearchBox.webpart file and copy the xml in clipboard and replace with the contents in <AllUsersWebPart WebPartZoneID="TopZone" WebPartOrder="1"> <![CDATA[ …old contens should be replaced with new
]]> </AllUsersWebPart>

Similarly open SearchCoreResults.webpart file and copy the xml in clipboard and replace with the contents in <AllUsersWebPart WebPartZoneID="BottomZone" WebPartOrder="3"><![CDATA[ old contents should be replaced with new from webpart file

]]> </AllUsersWebPart>

NOTE: make sure you replace the correct xml.  
Compile your project, deploy the .wsp and activate the web-scope feature that will create customsearchresults.aspx search result page with your customization.
There is another way as well … that is totally using C# code in the feature. I will blog it later…stay tuned.
Happy coding!