In my recent project we have implemented the same logic as we want scope searches in SharePoint 2010 to be sent over to the new 2013 farm.
I have improved on Tarjei’s solution with the following points:
- Display title of the site instead of just the URL (or list title as we support 2010 redirects to 2013 search)
- Implement as a generic script to be added anywhere on the page – preferably in the control template, but for this post I’ll do it as a script web part.
// Get a reference to the DataProvider for the page var dp = Srch.ScriptApplicationManager.get_current().queryGroups.Default.dataProvider; // Add event to be called after results are ready dp.add_resultReady(showScopeHint);
The advantage by using the search center instead of osssearchresults.aspx is that you can control which refiners you show and tap into whatever query rules you have defined on your search center site collection (because I know you have a separate site collection for your search center right?).
If you pass in the u= parameter to a search center you will get results from that scope only, but no UI indication.
With my added script it looks like the image below, where the site title is hyperlinked with the scope URL, providing a way to navigate back to the site collection you searched from.
You can add the script via your master page, as a content editor web part or a script editor web part. Note that it requires jQuery for ajax calls and DOM manipulation.
Get it from the SPCSR Github repository.
And to set up contextual search on a site collection and point it to your search center.
- Go to _layouts/15/enhancedSearch.aspx?level=sitecol
- Enter the URL to your search center as Search Center URL
- Enter {SearchCenterURL}/results.aspx?u={contextUrl} as the custom page URL