Configure to Search only in a specific list or document library in SharePoint 2013

While working for different clients,  I have found that the most common requirements of all by the customers is to enable users to search only in a particular SharePoint List or document library. In this blog, I will show how you can setup your result source to target a specific list or document library. However, in this post I willn’t explain how to create custom display templates to change the look and feel of how search results should display.

Creating a Result Source to search in a list

  1. Go to Site Settings. Under ‘Search’, click on ‘Result Sources’.
  2. Click on ‘New Result Source’. Give a Name to the result source, choose the ‘Protocol’ as ‘Local SharePoint’ and ‘Type’ as ‘SharePoint Search Results’.
  3. Now, launch the query builder under ‘Query Transform’.
  4. Type the following query text –

{SearchBoxQuery} (Path:http://[siteurl]/lists/[yourlistname]) (contentclass:STS_ListItem)
{SearchBoxQuery} – This indicates the search text entered by the user

Path: – Path is the managed property that indicates the url of the sharepoint list to be searched.
contentclass: Adding STS_ListItem as contentclass instructs sharepoint search to search only in the sharepoint list forms and not in the list view pages such as ‘AllItems.aspx’ etc.

Creating a Result Source to search in a document library

  1. Repeat steps 1 through 3 as shown above.
  2. In the query builder, the query text wouls also be same as for the list except the url would change to point to the document liberary such as

{SearchBoxQuery} (Path:http://[siteurl]/[DocLibraryName]) (contentclass:STS_ListItem)

However, the query above would also search within the documents stored in the document library. To restrict the search from searching content within the documents, use the query shown below –

{SearchBoxQuery} (Path:http://[siteurl]/[DocLibraryName]  FileExtension<>docx) AND (Path:http://[siteurl]/[DocLibraryName]  FileExtension<>pdf) AND (contentclass:STS_ListItem)

Unfortunately, in the query text we need to explicitly mention all the file extension types that needs to be ignored while searching by adding FileExtension<> [fileextension].


Leave a Comment

Your email address will not be published. Required fields are marked *