Create and use custom result source in content search web part in SharePoint Online
Check out Best Alternative to InfoPath -> Try Now
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.
SharePoint 2016 Tutorial Contents
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.
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“.
And if you want to create a custom result sources at a site level then click on “Result Sources” which is under “Search“.
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.
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“.
Now in the Query Transform click on “Launch Query Builder” like below:
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:
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:
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 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:
Then click on Save which will create our custom result source which we can see under the Manage Result Sources page like below:
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:
- JQuery News Ticker using content search web part in SharePoint 2013
- JQuery accordion using content search web part in SharePoint server 2013
- Bind SharePoint list data using jQuery datatable using content search web part CSWP in SharePoint server 2013
- JQuery Tabs using content search web part in SharePoint 2013
- Create a simple bootstrap navigation menu using content search web part in SharePoint 2013
- Content Query Web Part and Content Search Web Part in SharePoint 2013
- SharePoint 2013 Online Content Search WebPart with Query String
- Show Slideshow list data using SharePoint 2013 content search web part
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:
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:
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 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.
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.
SharePoint Online FREE Training
JOIN a FREE SharePoint Video Course (3 Part Video Series)