Create and use custom result source in content search web part in SharePoint Online

Here we will discuss how we can create a custom result source in SharePoint Online Office 365. Then we will discuss how we can use the custom result source inside a content search web part in SharePoint online.

Result Sources in SharePoint Online

SharePoint provides result sources by using which we can limit search results to specific content. When the user performs a search, the system matches the query with a result source to provide results. SharePoint comes with many preconfigured result sources for you to use, including Conversations, Documents, and Pictures etc.

We can also create custom result sources at various scopes like:

  • Service Application Level / SharePoint Admin Center for Office 365: When we create result scope at search service application level, the result source will be available to any site collection that consumes the Search Service Application.
  • Site Collection: When we create result scope at the site collection level then the result source can be used by any site within the site collection.
  • Site: When we create result scope at the site level then the result source can be used by that site only.

Create Custom Result Sources in SharePoint 2013

We can create a custom result sources at the site collection level as well as site level in SharePoint Online Office 365. To create custom result sources at the site collection level go to the Site Settings and then click on “Search Result Sources” which is under “Site Collection Administration“.

Custom result source sharepoint 2013

Custom result source SharePoint 2013

And if you want to create a custom result sources at a site level then click on “Result Sources” which is under “Search“.

result sources sharepoint 2013

result sources SharePoint 2013

Here we will create a custom result source for Site level. So click on Site settings and then click on “Result Sources” which is under “Search”.

This will open the Manage Result Sources page, here click on “New Result Source” like below:

Here on this page also you can see lots of default result sources as well as custom result sources.

how to create custom result source sharepoint online

how to create custom result source SharePoint online

Here in General Information section give a Name, Description for the custom result source. Then Protocol as Local SharePoint. And Type as “SharePoint Search Results“.

sharepoint online create custom result source

SharePoint online create a custom result source

Now in the Query Transform click on “Launch Query Builder” like below:

sharepoint 2016 create custom result source

SharePoint 2016 create the custom result source

This will open the Query Builder where we can build the search query. Here we will modify the Query text like below:

When we are writing the query like below:
path: “https://onlysharepoint2013.sharepoint.com/sites/Bhawana/MySearchTestDocLib/

We are telling that we only want results from the specified path and anything under it like folders, subfolders or subsite etc.

But we will modify the query a bit to search only a particular type of file like docx file.

path: “https://onlysharepoint2013.sharepoint.com/sites/Bhawana/MySearchTestDocLib/” FileType:docx

The FileType property instructs the query to only return files that have a .docx extension. The full query looks like below:

content search web part with custom result source

content search web part with custom result source

You can also click on the Test Query button to see the result like below, where it will display only docx files.

how to use custom result source in content search web part

how to use custom result source in content search web part similarly, if you want to add multiple filters then you can add like below:

path: “https://onlysharepoint2013.sharepoint.com/sites/Bhawana/MySearchTestDocLib/” FileType:docx FileType:txt FileType:pdf

Only you save the query then now Query Transform and Credential Information will look like below:

how to use custom result source in content search web part

how to use custom result source in a content search web part

Then click on Save which will create our custom result source which we can see under the Manage Result Sources page like below:

show only specific document sharepoint 2013 custom result source

show only specific document SharePoint 2013 custom result source

Now our result source is ready and in the next step, we will see how we can use it in a content search web part.

How to use Custom Result Source inside a Content Search Web Part?

Now we will add a content search web part to a web part page. If you are new to the content search web part, then you can see a few articles below:

You can create a web part page in SharePoint 2013. And then edit the page and then from web part categories Content Rollup choose Content Search like below:

How to use Custom Result Source inside a Content Search Web Part?

How to use Custom Result Source inside a Content Search Web Part?

Once the web part added, the web part will display recently changes items. Now edit the web part properties. In the Content Search web part properties, click on Change query like below:

content search web part SharePoint online

content search web part SharePoint online

This will open the Build Your Query window and here click on Switch to Advanced Mode.

content search web part SharePoint 2016

In the Advanced Mode, in the Select a query, you will be able to see the custom result source which we have created. Choose it and if you will click on Test Query you will be able to see the results also.

custom result source to show only word or pdf document sharepoint 2013

custom result source to show the only word or pdf document SharePoint 2013Click on OK and Save the Page, you can see the search results like below where it will only show word documents.

SharePoint 2016 custom result source content search web part

SharePoint 2016 custom result source content search web part

Hope this will be helpful to create custom result source and add a custom result source to content search web part in SharePoint Online Office 365.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>