Configuring contextual search to use search center
Posted
Thursday, December 9, 2010 10:25 AM
by
CoreyRoth
I’ve never been a fan of the way contextual search is handled in SharePoint out-of-the-box. By default, SharePoint has contextual searches go to OSSSearchResults.aspx. If you aren’t familiar with the term contextual search, you might be familiar with the This Site or the This List search scope options that you see in the search drop down list.
The reason I don’t like OSSSearchResults.aspx (besides all of the S in the page name) is that it is an application page and is generally considered not customizable. This means if you want to configure how results are displayed or the refinement panel, you really can’t directly (without leaving yourself in an unsupported state). You can make a copy of it and then make customizations, but that is a lot of effort for something so simple.
I understand why SharePoint uses this page by default though. The first reason is that SharePoint Foundation does not have a Search Center site template and it needs some place to render search results. Secondly, even if you have SharePoint Server, you may not have created a search center. Therefore, it uses this page by default so that search will work without any major configuration.
We want to customize what is on the contextual search page though. What you can do is reconfigure the Site Collection Search Results Page URL to point to your search center. We can find this setting in the Search Settings page of your site collection settings. I talked about these settings in the past. When you go to this page, you will see that the URL configured is /_layouts/OSSSearchResults.aspx.
We simply change this to the URL of the results.aspx page in your Search Center. Now, typically I install my search center on a URL such as /Search or /SearchCenter. Determine what your URL is or go create a search center using the New Site menu. In my example, we'll use /search. You will find the results.aspx page in the Pages library, so the full URL we want is /Search/Pages/Results.aspx. You can also determine this URL by going to your search center and performing a search. When you enter the URL, leave out the server name.
Once you have finished, we can test our contextual search from any site or document library.
As you can see, our search results are now in the Search Center and we have things like people search showing up. However, the results only contain the contextual information from the subsite. Now, I can customize this page as needed. The CoreResultsWebPart actually uses two extra query string parameters to make this happen. The cs parameter has the contextual scope name, This Site. The u parameter specifies which URL to limit the results to. As always, the k parameter contains the query itself. This is a simple customization to implement and I highly recommend it if you want to customize your contextual search results.