I could play a game of “state the obvious” and say that SharePoint 2010 search is powerful. It’s really an incredible beast – and that’s even without any FAST goodies in there. But something that isn’t obviously supported OOTB but seems there’s a few people out there trying to do – search within folders, or in my case, Document Sets. SharePoint search was already configured and, actually, I could search within document sets, by doing a site wide search and then using the refinement panel (on the left hand side of a search result page in a search center) to narrow it down to my document set. What I wanted to do was perform this search directly from a search box.
As you use the refinement panel, you’ll notice that the URL changes, as you stack up the filters, and as it happens, that’s all that’s required is a properly crafted URL:
Note the highlighted part – you can restrict your search results to a specified document set (or folder) by supplying the URL in to the site: refinement option/filter.
With that bit taken care of, the challenge was to get a searchbox that would do this dynamically – i.e., craft the URL properly to apply the filter and direct through to the search results page properly. It’s possible using a standard search box and the trusty old Content Editor.
The standard search box enables you to append anything you like to a query using the “Additional Query Terms” property of the webpart. The trick is to get it to dynamically set the URL of the folder you’re looking at, so it works on every page. This assumes that in the URL of the page, you have a parameter called RootFolder which contains the full path to the folder or document set that you want to search in.
1. Edit your page, and add a standard search box, and a content editor webpart. Reposition the content editor so it appears after your search box.
2. Edit the properties of your search webpart so that it looks like this.
3. Edit the HTML source of your Content Editor:
And add the following script:
And that’s about it. Enjoy.
Props: I got the “GetUrlVals” script from Ashley Ford.