Custom Search in SharePoint using OOTB features and Open Source webparts


As we all know, Search is extremely important in SharePoint. We have a lot of features out-of-the-box ready to help us configure a great Search, but we also have a great community out there working/contributing to open source Search webparts!

In this post, we’ll configure a custom Search. We’re going to scope it to a few Site Collections, and add the PnP Modern Search Webparts which are open sourced on Github.

Official Documentation
Here is the official documentation link if you want to know more.

In this scenario, we’re going to create a (blank) Communication Site. I find the design much better than a team site for a separate Search.

Deploy the PnP Modern Search webparts

If you navigate to the Github repository for the PnP Modern Search, go to releases, and download the latest package (pnp-modern-search-parts.sppkg) under “Assets”.

Latest version
At the time of writing this post, we’re on version 3.8.0 from December 2019. Visit the Github repository for the latest version.

Navigate to the App Catalog (hopefully already created in your tenant), and upload the .sppkg package.


Then click on “Deploy” when prompted, and the package will be deployed.


Add the webparts to the Search site

Now’s the time to add those webparts to our custom Search! Navigate to the Custom Search site –> click on the “gear icon” –> Add an app.

And there it is! 🙂


Click on it, and wait for a few minutes for the app to be added to the site and be available amongst the webparts (until it’s not greyed out anymore)

Once they are available, you can add them to the site by editing the page.


Choose a layout for the Search site

I usually go for a 1-third right layout (2 columns), so I can have:

  • Verticals
  • Search Box
  • Search Results
  • Refiners (on the right)
  • Search pagination

But this entirely up to you how to organise according to your preferences.


Each webpart has a configuration panel that you can use to your liking. Just click on Edit and a blade will open on the right.


Scope the Search Results with Result Sources

Now we can scope the results so users only see content from specific Site Collections.

On the Custom Search site, navigate to the gear icon –> Site information –> View all Site Settings. Under Search, click on Result Sources.

We are going to create a new result source and add 2x specific site collections. In the Query Transform section, click on Launch Query Builder.

The below query will only target the 2x URLs mentioned, and remove any “views” from the results (-contentclass:STS_List_*.)


By clicking on Test Query, you can have a preview of what the results would look like. Then click OK and Save.

Our new result source has been created, but one more thing: grab the ID of that result source for our Search Results webpart configuration.

Click on the result source –> look at the URL –> the end is the ID number (ex: sourceid=ab12345-cd678-…….)

Configure the Search Results with the Result Source ID

After configuring the other webparts (Verticals, Refiners…) to connect to the search results, let’s configure the Search Results with the Result Source Identifier. Edit the page, then the webpart, and on page 2, enter the ID we copied earlier.


The refresh is dynamic, so you don’t need to publish the page to see what it looks like! There’s no save button, simply close the panel.

The results are now scoped to those 2 site collections, and below is an overview 😋


Happy customisation!