Limiting Search For A Specific Library In SharePoint 2013

Recently, I got a requirement to limit the search result pages to show data from a specific document library only. Prior to SharePoint 2013, it was handled/achieved by configuring the Search Scope. However, in SharePoint 2013, we can achieve it using Result Sources. You can find more details about the result source here.

Please follow the below steps to achieve the functionality (“Limit search result for specific Library”).

Step 1 - To check/Test we need Search box web part and Search Result Web part

Create a Page.

Add Search Box and Search Results web parts.

Got to Categories - Search - Select “Search Box ” Web Part, then “Search Results” Web Part.

Limiting Search For A Specific Library In SharePoint 2013 
 
Limiting Search For A Specific Library In SharePoint 2013 

Step 2 - Create a Result Source

Go to Central Admin - General Application Settings - Search.

Under “Queries and Results” Select - Result Source.

Limiting Search For A Specific Library In SharePoint 2013 

The "Manage Result Source" page will get open. Now, click on the "New Result source” button.

Limiting Search For A Specific Library In SharePoint 2013 
Limiting Search For A Specific Library In SharePoint 2013 
Name your result source. Leave the "Protocol" radio button set to “Local SharePoint” as we’re searching local content.

Set the "Type" radio button to “SharePoint Search Results”.

Limiting Search For A Specific Library In SharePoint 2013 
Next step is to create a search term. Click on the "Launch Query Builder" button to configure the query.
Limiting Search For A Specific Library In SharePoint 2013 
In a Query text, add the path with {SearchTerms} and full path of the specific document library.
Limiting Search For A Specific Library In SharePoint 2013 

Example

{{searchTerms} Path:”https://siteUrl/SearchDocumentsLibrary/” }

Click ok for Query Builder

Click save Button

Step 3 - Next step is to configure Search Results web part

Go to your search result page

Edit the page >> Edit Search Results web part

Now, in "Properties" for Search Result, click on the "Change query" button. A "build your query" pop up will open.

Limiting Search For A Specific Library In SharePoint 2013 

Select the “Basics” tab.

Now here, in "select a query" dropdown, we can select the newly created custom result source.

Limiting Search For A Specific Library In SharePoint 2013 

Click OK.

Publish your Search page.

Type any keyword in the search box and hit Enter.

Closely observe that the search result is only showing the documents which belong to the specific library.