Thumbnail Quick tip: customizing the SharePoint site search experience

Quick tip: customizing the SharePoint site search experience

This post is about highlighting a nice feature in SharePoint: Modifying the default SharePoint site search experience. Among other reasons so I don’t forget it myself 😁. It’s really easy, and can offer a significant improvement in user experience in many scenario’s.

When you create a new SharePoint site, you get a nice dynamic Microsoft search box in the middle of the Suite bar. The search box is available on other browser-based Microsoft 365 applications, giving it a nice and consistent feel. This search box can be used to search within a site or within lists/libraries on that site. If you use it to search the site, you’ll be sent to a default results page:

default-search-results

This page is not very flexible though. You can’t edit it to add your own webparts to integrate it more into your own system or SharePoint setup.

Also, the page has a specific Layout type called HeaderlessSearchResults, which means that there is no header, but also that any site quick launch / top navigation is not visible. This creates a more roomy feel, but it also means you’ve lost the context of your site, and it has become less easy navigating to the other parts.

To change this, you can create your own search results page and use that instead.

Creating a custom search results page is easy. You can do it manually, or you can use PnP PowerShell to do it for you. After creating an empty page, you can assign it as the search results page using the following script:

Add-PnPPage -Name Search.aspx -LayoutType Article -CommentsEnabled:$false -Publish -HeaderLayoutType NoImage -Title "Search"
Set-PnPSearchSettings -Scope Site -SearchBoxPlaceholderText "Search in site/organization" -SearchPageUrl "$siteUrl/SitePages/Search.aspx"
Set-PnPSearchSettings -Scope Web -SearchPageUrl "$siteUrl/SitePages/Search.aspx"

As you can see I’m setting the search page URL to Search.aspx, which is an empty site page I’ve created. I’m also modifying the placeholder text of the search box. This is optional, but it’s a nice way to give the user a hint on what to search for. This becomes especially handy in situations where your sites are containers for specific business entities, like projects, customers, etc. Search in project is far more clear to a user than the default text is.

search-placeholder

After using the search bar, we’re now redirected to the new Search results page, which I’ve filled with some webparts from the PnP Modern Search open source solution. I’ve added a verticals-webpart to differentiate between results from the site and the organization. I’ve also added a horizontal filters webpart and of course a results webpart.

custom-search-results

As you can see I’ve not set the layout to HeaderlessSearchResults, so the site navigation is still visible, which is quite nice. There is less room though. So depending on the typical usage/screen sizes in your company you might influence the way you configure the page.

The powerfull thing here is that you can configure this page in any way you want. You can allow users to search the current site, or a series of sites, for example if your site is part of a business entity, like projects. You can also add specific search filters to the page, to allow users to filter the results in a way that’s useful with certain company metadata.

And that’s it already! Just a quick tip really.

It’s is a very simple setup, but depending on your goals and your setup on SharePoint, you can really make a difference here for usage and adoption of your SharePoint environment.


sharepoint powershell search
Support me by sharing this

More

More blogs

Correctly paging when searching SharePoint
Correctly paging when searching SharePoint

Avoiding an API pitfall when querying large result sets using SharePoint search

Read more
Automating Purview data retention using Azure Functions
Automating Purview data retention using Azure Functions

An example of how to automatically apply Purview retention labels using Azure Functions.

Read more
Working with Purview event-based retention using code
Working with Purview event-based retention using code

Do you want to retain data for a period of time after a certain event has happened? It is called event-based retention and this is how you use it from code.

Read more

Thanks

Thanks for reading

Thanks for reading my blog, I hope you got what you came for. Blogs of others have been super important during my work. This site is me returning the favor. If you read anything you do not understand because I failed to clarify it enough, please drop me a post using my socials or the contact form.


Warm regards,
Martin

Microsoft MVP | Microsoft 365 Architect

Microsoft MVP horizontal