I am trying to implment a search functionality in sharepoint which will scope of searching the entire sharepoint site.
1 Answer
We can customize the search both in SharePoint on-premise and SharePoint Online.
Search customization in SharePoint on-premise(display template - using Javascript, Jquery & REST API
When we talk about search customization in SharePoint on-premise (from SharePoint 2013 onwards), it is customizing the "Content Search" Web part.
In the content search web part, there are two templates item template and header template, these templates are available in the master page layout gallery, you will find it from the site settings page.
Download the item template from this location, the HTML version of the template file - rename it and write your JQUERY and REST API code here, you can read the data from SharePoint search service result.
Notes:
- You need to write the code in the commented section - it looks odd but this is the way to write.
- Advantage of customing the display template, since it works on the search service level, no need to handle the permission explicitly.
After customing the template file (HTML version) - upload the file in the same master page gallery library from where it was downloaded, then automatically a javascript version of this template file will be created - publish it.
Then go to the content search web part configuration, there you can see your customized display template, select that file - that's it, done !!!
You can refer to the below article for details steps on customizing the display template:
Steps To Create Custom Display Templates In SharePoint 2013
Customizing the SharePoint Search web part in modern SharePoint online site (using the SPFx PnP solution):
There is an awesome web part in the GitHub which was developed using the PnP SPFX - it is a similar version of content search web part which we have in on-premise but it is more flexible, robust and faster - easily configurable through the UI, there is very well descriptive documentation how to use this.
The modern PnP search result web part can be downloaded from here.
Supporting reference articles: