Tuesday, May 3, 2011

Using SharePoint 2010 Search Query String Parameters

SharePoint 2010 Enterprise Search query string parameters are almost exactly the same as they were in SharePoint 2007. However, I would like to highlight them, because they can be useful when directing custom links to a search page. You might want to do this if you are creating a custom search-based tag cloud, for example. You could code the tags in the tag cloud to link to the appropriate search page and include a refinement parameter in your query string (see below for more about the refinement parameter). This Microsoft page highlights most of the query string parameters:

There is another parameter that is not documented in the link above that is available on SharePoint 2010 Server. The r parameter (for refinement). Thanks Steve Curran for pointing this out here: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/5868ed16-7602-4251-b28f-310b479dd1ec
The refinement parameter is a little bit trickier than the other parameters because (as Steve mentions):
  • It must be URL encoded
  • It requires a k parameter to be present
The refinement parameter also requires that the field you are refining on be setup as a managed metadata property in the SharePoint Search Service.
So let's say you are using a server side code-behind to create a custom link to a search results page. It might look something like this in C# (replace bracketed items with your actual items):

string rParameter = System.Web.HttpUtility.UrlEncode("title=\"[Sample Title]\"");
string url = "[site collection path]/searchcenter/pages/results.aspx?k=[Sample]&r=" + rParameter;

The result is a string that looks like this (again, replace the bracketed information with your data):

http://[site collection path]/searchcenter/pages/results.aspx?k=[Sample]&r=%22title%22%3D%22[Sample Title]%22


  1. Hi Doug,
    i'm facing an issue with SharePoint Online. With the refine panel i get result for a managed metadata built on taxonomy term-store. When i click on a link to refine the search under the metadata breakdown panel i don't retrieve data.

    After some investigation i detected that the builtin link and related querystring does not work, but with a different syntax it works

    here a sample (Program is my field which gets value from the predefined termset)
    [this does not work]
    https://contoso.sharepoint.com/search/Pages/results.aspx?k=osisoft&r="owstaxIdProgram"=#10c280d9-5688-43aa-b8fb-6d96bf18500f:"23 SharePoint"

    [this work]
    https://contoso.sharepoint.com/search/Pages/results.aspx?k=osisoft&r=owstaxIdProgram:"23 SharePoint"

    I decode the Url for better reading but the result is the same with the encoded one

    any suggestions?


  2. Any idea why on the Enterprise search it wouldn't support '*' or wild pattern search?

    1. It supports wildcard pre match so sha* would find sharepoint for example

  3. Hello all. I need to make a query which will search for certain content types only. Eg: Say only videos that have the matching search keyword. how to write the r parameter for the same??