Hi @IM ,
I would suggest the you can use PnP Modern Search v4 to dynamically search within the hub site.
- Add PnP - Search Box and PnP - Search Results to the page, edit Search Results web part and use KQL filters
DepartmentId:"{hubSiteId}"
orDepartmentId:{{PageContext.hubSiteId}}
on the hub site.
- Connect Search Box to Search Results.
After finishing this, the Search Results will only return results within the sites of a hubsite when searching in Search Box.
To install and get started with PnP modern search, see these:
To retrieve the hubsiteId of a specific hub site, you can use the PowerShell command Get-SPOHubSite or via a SharePoint API call: /_api/site?$select=IsHubSite,HubSiteId
.
----------
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.