SharePoint Site Search Settings (Search Scope DropDown)

3 minute read

Today I was working on some SharePoint master pages and I noticed that the search scopes dropdown was gone. After searching around in the site collection administration settings I found a setting under the 'search settings' link.

searchsetting

The property 'Site Collection Search Dropdown Mode' can be set to several options. Default this property is set to 'Do not show scopes dropdown, and default to contextual scope'. In this setting you have the following options: Do not show scopes dropdown, and default to contextual scope. You will get result of the 'All Sites' scope when you are at the top level. If you are in another level you will get results from your context. Do not show scopes dropdown, and default to target results page The search results will be displayed as described above. It will only use your target result page for displaying the results. Show scopes dropdown Display's the scopes that are defined in the scope display group of the site. Show, and default to ’s’ URL parameter Displays the scopes that are defined in the scope display group of the site. This option will add the scope to the query string using the 's' parameter. Show and default to contextual scope Displays the scope drop-down list and selects the "This site" and "This list" by default. Show, do not include contextual scopes This option will not display the contextual scopes. Show, do not include contextual scopes, and default to ’s’ URL parameter This option will not display the contextual scopes, and will also send the scope within the query string using the 's' parameter. These settings can all be set trough the UI but in most situations we as developers need to set these properties within a feature receiver. When you search through the object model you will not find a possibility off doing it through code. The next option is to look with reflector in the code behind of the page and you will find a way to accomplish this task. Each site or web has a property bag by setting the "SRCH_ENH_FTR_URL" you set the search site URL of the site collection. And by setting the "SRCH_SITE_DROPDOWN_MODE" property you change the display mode of the search dropdown. Here below you can find an example in code:

 private void ApplySearchSettings(SPWeb web)
 {
       if(web.IsRootWeb)
       {
            string searchCenterUrl = (new Uri(web.Url).GetLeftPart(UriPartial.Authority)) + "searchcenter";
            web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = "ShowDD_DefaultContextual ";
            web.AllProperties["SRCH_ENH_FTR_URL"] = searchCenterUrl;
            web.Update();
       }
 }

The property "SRCH_SITE_DROPDOWN_MODE" has several options you can fill in:

  • HideScopeDD – Do not show scopes dropdown, and default to contextual scope.
  • HideDD_NoScope - Do not show scopes dropdown, and default to target results page.
  • ShowDD – Show scopes dropdown.
  • ShowDD_DefaultURL – Show, and default to ‘s’ URL parameter.
  • ShowDD_DefaultContextual – Show and default to contextual scope.
  • ShowDD_NoContextual – Show, do not include contextual scopes.
  • ShowDD_NoContextual_DefaultURL – Show, do not include contextual scopes, and default to ‘s’ URL parameter

For the scopes dropdown modes you can also look at the following URL in de SDK of Microsoft:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.portal.webcontrols.dropdownmodes.aspx