Monday, April 22, 2013

Limiting search results in SharePoint 2013 (aka scopes in 2010)

A typical scenario in SharePoint is to limit the results on a search page to specific content. In SharePoint 2010 this was achieved by creating Search Scopes, and then adding include and exclude rules to the scope. Then you could configure the Core Results Web Part to display results from that scope only.

SharePoint 2013 however introduces the concept of Result Sources instead of scopes. As a sample I will limit results to show items from one particular site.

You can create Result Sources on three different levels: Search Service Application, Site collection and Site. This means you can define Result Sources in a very granular way, depending on where you want to use them. But bear in mind that having configurations spread all across your sites increases complexity of maintenance. In this sample I will create my Result Source at the SSA level.

Steps

Navigate to your SSA on Central Admin and click Result Sources in the left hand menu.
image

Next click “New Result Source”. This would be equal to a new search scope. Give the result source a name, leave the radio button on “Local SharePoint” as we’re searching local content. The limiting rule is then added in the Query Transform box. You can either launch the Query Builder or manually append your limiting query to the user query.

In this sample you will end up with the query:

{searchTerms} path:http://intranet.contoso.com/sales

{searchTerms} is a placeholder for the user query, and the last bit will make sure only items starting with http://intranet.contoso.com/sales are included.

image

Finally you will save the newly created Result Source.

Now that you have create the Result Source (or scope) you need to configure your search page to use it. Navigate to your search result page and enter edit mode. Next edit the Search Results Web Part and click the Change query button.
image

In the query builder dialog you can now choose your new result source in the top dropdown.

image

Click OK, save your page, wait a few seconds for the change to be picked up and results should be limited to http://intranet.contoso.com/sales.

Not too hard, just a bit different from what you were used to in SharePoint 2010.