Archive

Search Service

The search settings for SharePoint sites, site-collections or even for the entire farm can be set through PowerShell. In SP 2010, there were 3 properties which had to be set for a site in order to configure the search box setings: “SRCH_ENH_FTR_URL”, “SRCH_SITE_DROPDOWN_MODE”, “SRCH_TRAGET_RESULTS_PAGE” – for more details, refer to this post. In SharePoint 2013, this has slightly changed, and I have also looked in more depth, to see how the search box works, and how it retrieves its settings.

The search box we see by default in all SharePoint sites is a control registered in the master page by some of the standard SharePoint features. The delegate control id is “SmallSearchInputBox” and three SharePoint features register controls here:

  • ContentLightup, with sequence number 100
  • OSearchBasicFeature, with sequence number 50
  • OSearchEnhancedFeature, with sequence number 25

Considering “SmallSearchInputBox” does not all multiple controls, only the registration with the lowest number gets taken into account. Here is how it looks like:


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <Control
 Id="SmallSearchInputBox"
 Sequence="25"
 ControlClass="Microsoft.Office.Server.Search.WebControls.SearchBoxScriptWebPart" ControlAssembly="Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
 <Property Name="UseSharedSettings">true</Property>
 <Property Name="RenderTemplateId">~sitecollection/_catalogs/masterpage/Display Templates/Search/Control_SearchBox_Compact.js</Property>
 <Property Name="EmitStyleReference">false</Property>
 <Property Name="ServerInitialRender">true</Property>
 <Property Name="TryInplaceQuery">false</Property>
 <Property Name="QueryGroupNamesJson">[&quot;MasterPage&quot;]</Property>
 <Property Name="ChromeType">None</Property>
 <Property Name="ID">SmallSearchInputBox1</Property>
 </Control>
</Elements>

The search box is rendered by a web part called SearchBoxScriptWebPart , which has several properties that can be changed – i.e. the render template uses a script file “Control_SearchBox_Compact.js”, you can change the property to point to your custom file. In order to change the default way the search box is rendered, or maybe use a different search box control, you would have to register a new delegate control with a lower sequence than 25.

But how does the default web part work, and how can we configure it? The web part takes it settings from a settings object: SharedSearchBoxSettings . This configuration can be set at four different levels:

  • Web: It looks for a property of the current web with key “SRCH_SB_SET_WEB”
  • Site-Collection: It looks for a property of the root web with key “SRCH_SB_SET_SITE”
  • Tenant: it looks for a site subscription property with key “SRCH_SB_SET”
  • Search Service Application: it looks in the search service application for the SharedSearchBoxSettings property.

All these properties contain a serialized string of a SharedSearchBoxSettings object: e.g. “{"Inherit":false,"ResultsPageAddress":"http://spdevel.portal.com/search","ShowNavigation":false}“. In a previous post, I have explained how to use PowerShell to update these web properties. The search box web part starts looking for the settings at 1st level, then goes to 2nd level and so on until it finds a configuration. When it finds a configuration, it will not look at the next levels. Because of this, you can overwrite the search box settings at any level.

The search box results address Url can be set at the following levels:

  • SharedSearchBoxSettings: from ResultsPageAddress property
  • Web: from web property “SRCH_ENH_FTR_URL_WEB”
  • Site collection: from root web property “SRCH_ENH_FTR_URL_SITE”
  • Search Service Application: from Search Center Url property

A simple configuration scenario would be to set up a search center for all sites & site-collections in the farm, and to disable the search drop down scopes. In this scenario, you would also have a centralized place for your search settings.. You only need to set the search box settings at the Service Application level, and leave all sites/site-collections to inherit this configuration:


$ssa = Get-SPEnterpriseSearchServiceApplication
#replace {SearchCenterUrl} with the Url of your search center
#settings ShowNavigation to false will not display the search scopes anymore.
$ssa.SharedSearchBoxSettings = "{'Inherit':false,'ResultsPageAddress':'http://{SearchCenterUrl}/pages/results.aspx','ShowNavigation':false}"
$ssa.Update()