Thursday, August 17, 2023

PnP Modern Search Office Hours - Online tips and advise

 

For some time, I have assisted the PnP Modern Search project by answering questions and handling bug reports.

However written communication is often not optimal to describe the issue you are facing which has been a blocking bug for several weeks now. And if you are new to SharePoint/Microsoft Search there are a substantial number of pitfalls that can prevent your progress.





Therefore, I am now offering:

PnP Modern Search Office Hours - Online tips and advise 

Every 2nd week I will offer 4 slots of 15 minutes each (for free of cause) where I will set up a Teams Meeting with each participant. The sessions will be 1:1 and will not be recorded, and using screen sharing we should be able to pinpoint the issue and get you going again. 


So, if you are stuck on a Search related issue or need some advice regarding Search feel free to sign up  in this MS Form



The first session is August 22 @16.00 UTC+1



PnP Modern search: Set refiners in the URL

 

The PnP Modern Search Filter web part supports deep URL linking, so if you provide the correct URL both the Search text and selected filters can be activated once the page loads:









However, getting the correct URL can be tricky. The recommended approach is to set the search text and the relevant Filters and then grab the browser URL. It will look like this:


https://[Tenant].sharepoint.com/sites/PnPModernSearch/SitePages/Filters-read-from-url-are-not-set-in-the-filter-web-part--3157.aspx?q=cmo&f=%5B%7B%22filterName%22%3A%22RefinableString09%22%2C%22values%22%3A%5B%7B%22name%22%3A%22CMO%22%2C%22value%22%3A%22%C7%82%C7%82434d4f%22%2C%22operator%22%3A0%2C%22disabled%22%3Afalse%7D%5D%2C%22operator%22%3A%22or%22%7D%5D#

The components are: the URL to the page + the q section + the f section.

The q section is just the text to be applied in the Search Box. 

The f section is the Filter settings. It looks pretty messy, but this PowerShell snippet will clean it up:


$url = Read-Host "Enter URL"

$pageURL = $url.Substring(0, $url.IndexOf("?"))

$filterURL = $url.Substring($url.IndexOf("?")+1)

$filterURL = $filterURL.Replace("%5B", "[")

$filterURL = $filterURL.Replace("%7B", "{")

$filterURL = $filterURL.Replace("%22", '"')

$filterURL = $filterURL.Replace("%3A", ":")

$filterURL = $filterURL.Replace("%2C", ",")

$filterURL = $filterURL.Replace("%5D", "]")

$filterURL = $filterURL.Replace("%7D", "}")

$filterURL = $filterURL.Replace("%C7%82%C7%82", "ǂǂ")


$newUrl = $pageURL + "?" + $filterURL

$newUrl


And once cleaned up it looks like this:

f=[{"filterName":"RefinableString09","values":[{"name":"CMO","value":"ǂǂ434d4f","operator":0,"disabled":false}],"operator":"or"}]


The value tag above is the Filter Token, and you will be able to find those using the SP Search Query Tool.