While working with SharePoint search solutions, we might come across a scenario where we are required to limit the search results to specific content. There were Search scopes in SharePoint 2010 to achieve this. The Search Scopes were replaced with the "Result Source" in SharePoint 2013. The purpose of this article is to create a custom Result source and we will take a simple example of limiting the search results to a specific document library in our site collection using result source.

I am using a SharePoint online site collection for the example and all the search configuration for result sources are done in tenant administrator. The similar settings can also be done in an On-Premise SharePoint environment. So lets get started.

Create sample data for search

To get some results in search, I created some sample files. A file in shared documents library and a PAGE in Pages library.

Test the search results with SharePoint search webparts

Notice that both the items have "Landscape" keyword in their title, and that is the keyword on which we are going to search in this example. Now, these items should be crawled in order to be able to fetch them in search results. I don't have to bother about the crawling as I am working with Office 365, where we do not have control over the crawl schedule and it is automatically taken care of. However, if you are working in an On-Premise environment, make sure you have crawled the site collection before proceeding ahead.

Now, we will insert the SharePoint search web parts on a page in our site collection.

Let us search with the keyword "Landscape" and we will see that both the items we created are retrieved in the search results.

Create and configure a new result source

The purpose of creating a Result Source is that we want to limit the search results only from the document library and ignore the results from PAGES library. Navigate to your tenant administrator and go to the Search administration page. If you are working in On-premise environment, Navigate to

Central Administration -> Manage service applications -> Search Service application -> Result Sources

The search administrator page in tenant administrator will look like this.

Click on Manage Result Sources and create a  New Result Source

Enter the details for the Result Source

Click on "Launch Query Builder"

As shown in the below image, select the property "Path", criteria "Contains" and enter the manual value as URL of the document library to which the search results should be restricted.
Several other criteria can be set as per the requirement to filter the search results.

Hit SAVE and our result source will be created.

Configure the search webpart to utilize the Result source

Now edit the search web parts that we inserted in the initial steps and set the Result Source of the  search results web part to the one we created.

Apply the changes, Save the page and again Search for the keyword "Landscape". Now, the results only from the "Documents" library will be fetched.

The Allitems.aspx page is shown because it is a part of the document library. This page can be trimmed in the search results. Have a look at Steve Mann's article here: http://stevemannspath.blogspot.co.uk/2013/04/sharepoint-2013-search-removing-junk.html