Tuesday, July 2, 2013

SharePoint 2013 Search: Setting All Search Boxes to Use Your Search Center

Search boxes that appear on your sites and sub-sites will automatically render local results first and if you have the global search center set in your Search Service Application, a link appears to "expand your search" which then navigates to your search center.

You may configure the search boxes to navigate to your search center at both the site collection and site level. This is performed under Site Settings -> Site Collection Administration -> Search Settings for the site collection and Site Settings -> Search -> Search Settings for the site level. If you configure these settings at the site collection level, the same settings will be used for all sites within the site collection unless modified.

In setting up our new SharePoint 2013 farm, navigating through hundreds of site collections to modify these settings was not an option. Therefore I wrote a simple PowerShell script to loop through all site collections within a given web application and apply the search center URL and result page to them:

$SPWebApp = Get-SPWebApplication http://sp2013
foreach ($SPSite in $SPWebApp.Sites)
{
    if ($SPSite -ne $null)
    {
        $web = Get-SPWeb $spsite.Url       
        $web.AllProperties["SRCH_SB_SET_SITE"] =  

                {"Inherit":false,"ResultsPageAddress":"/sites/SearchCenter/Pages/results.aspx","ShowNavigation":false}'
        $web.AllProperties["SRCH_ENH_FTR_URL_SITE"] = '/sites/SearchCenter/Pages'
        $web.Update();

    }
}


EASY!


I found a post here that shows how to loop through each sub-site (SPWeb) and set the settings at the site level, however, I believe I have achieved my goal just by setting these values at the site collection level.



 

4 comments:

  1. Rohit: Hi, In sharepoint 2013, the search can be configured at 3 levels.
    you know about Site and Web level.
    but in central admin , while configuring your search service application, you can provide global search url there.. all site collection will automatically inherit it.

    ReplyDelete
    Replies
    1. Steve , Please correct me, why we need to set global search url here for every web, in a loop, why not to set directly in central admin. ?
      I googled for removing $web.AllProperties["SRCH_SB_SET_SITE"] with powershell. not getting it.. can you please tell how to make it NULL, EMPTY, or to remove it.

      Delete
    2. The search box on our migrated sites would only search the current site but then provide a link to the search center. We wanted all search boxes to go to the search center and not show local search results.

      Delete
  2. Great script - just a minor fix:

    There is a ' missing in $web.AllProperties["SRCH_SB_SET_SITE"] assignment.

    Cheers
    Max

    ReplyDelete

Matched Content