Forum Discussion
Configure modern search results to search all of your organization (rather than the current site)
Hey everyone,
We heard from many of you the need to be able to change the scope of your modern search results pages. When you create a new communication site or team site in SharePoint Online today, and type into the search box, you are taken to the modern search results page. This page shows results from your current site by default, and allows you to expand the scope of your search to the hub that the current site is associated with (if there is one), or to the whole organization.
But there is a desire for being able to change the behavior to always search over the whole organization, or across the hub a site is associated with, without needing an additional click, especially if the site in question will be used as a modern landing page for your organization.
I'm happy to say that with the latest version of the SharePoint PnP PowerShell extensions, it is possible to run a simple command as the site owner, and make your site use the organization, or the hub scope by default.
To change this setting:
1. Start PowerShell in administrator mode as you will be installing the PnP extensions.
2. Run the following commands to in this order:
PS C:\WINDOWS\system32> Install-Module SharePointPnPPowerShellOnline
# If you previously had installed this module, you may need to use the "-Force" parameter to install the newer version.
PS C:\WINDOWS\system32> Connect-PnPOnline -Url https://contosodemosg.sharepoint.com/sites/Strategy -UseWebLogin
# this will prompt you to sign into your site. Use the site owner credentials to sign in
PS C:\WINDOWS\system32> $web = Get-PnPWeb PS C:\WINDOWS\system32> $web.SearchScope = 1
# 1 for Tenant, 2 for Hub, 3 for Site, 0 for default behavior
PS C:\WINDOWS\system32> $web.Update() PS C:\WINDOWS\system32> Invoke-PnPQuery
After running these commands, the site will start to show results from the whole organization.To go back to the default setting, run the commands again with the value provided to "SearchScope" parameter to 0.
To search across the Hub, use 2 as the SearchScope value.
We will be providing a way to set this setting using the UI in a future release as well.
Updated in April 2020 to reflect the ability to search across Hubs.
Hi Rick DeFoe, we are actually working on making that happen. We hope that will be coming in the next couple of months.
- Rick DeFoeIron ContributorIs there a way to change the scope to be just the sites in the hub? This would allow you to set all hub sites to have the same search scope as the root hub site.
- Kerem YuceturkMicrosoft
Hi Rick DeFoe, we are actually working on making that happen. We hope that will be coming in the next couple of months.
- Rick DeFoeIron ContributorKerem Yuceturk Is there any update on being able to set the scope to be sites in the hub? I tried it recently and it doesn't seem to work yet. My understanding is you were working on this and eventually a value of 2 for DefaultScope would do this.
Thanks
- Hi Kerem,
Will this also be added to the sitescript actions soon? That’s in my opinion more important then having it available through the UI.- Kerem YuceturkMicrosoft
Hi Robert Schouten, not right away, but some of my colleagues are working on adding the ability to set properties and turn on features. Hopefully that will be available later this year.
Robert Schouten, in the meanwhile you could make the site script to start a flow and from that flow call an Azure function that runs the PowerShell script.
Laura
Laura Kokkarinen yes I know that road. At some customers, an Azure environment is not always available. But if it is, it a very valid option! Tnx...
- Max GossBrass ContributorHi Kerem, this is a really useful feature, and will enable search on intranet sites to behave much more consistently. Thanks for enabling this!
Are there any plans to be able to modify the search settings to search the hub by default? For example if we have several Intranet sites connected to a hub it would be great if we could have an option to have all connected sites search all content in the hub by default. Ideally this would still bring back Promoted results which currently I know only feature if a global search is performed. Are there any plans for this?- Rick DeFoeIron ContributorI am hoping for this as well. We have just launched a new SPO intranet using modern SPO and hub sites and users are confused when searching from the hub vs searching on a child site.
I have been lead to believe they are working in this, and was told the following parameters values will eventually work for the various search scopes. I would love to get an update to know if it is still planned
DefaultScope = 0,
Tenant = 1,
Hub = 2,
Site = 3
- ArefHalmstrandSteel Contributor
Kerem Yuceturk
Here is also an video instruction for those who would like to see how to configure modern search results.
https://www.youtube.com/watch?v=6WS2vkYqs7g&ab_channel=ArefHalmstrand
Yours sincerely,
Aref Halmstrand - AGoneauBrass ContributorWhat would be really nice would be a drop down menu in the search box that allowed the user to select their own scope (this site, this hub, organization, people, etc).
- DenisTIron Contributor
- HaroldvandeKampBronze Contributor
Thank you for adding this feature. Often requested by our customers. Just tried it out and worked directly as I expected.
- Joe VolkBrass Contributor
Kerem Yuceturk This looks great! I am trying to implement it and run into an issue when trying to connect to the site. We have single sign on enabled via SailPoint and when the browser goes to try and log me in I get a blinking screen and cannot get connected. Any suggestions?
- Kerem YuceturkMicrosoft
Joe Volk , sorry not familiar with that. My two factor auth works when I use -UseWebLogin. This page has more information about the PnP solution, and may have some discussions that might be helpful: https://github.com/SharePoint/PnP-PowerShell
- RenevdoCopper Contributor
Kerem Yuceturk It seems that searching trough the REST API, this setting is ignored.
This query for example, searches only in the current sitecollection on a modern communication site:
https://mytenant.sharepoint.com/sites/moderncommunicationsite/_api/search/query?querytext=%27test%27
See also this issue:
- Kerem YuceturkMicrosoft
Hi Renevdo, This is for the modern search results UI only. It has no effect on REST. You should be able to get to the scope that you want in REST in other ways like as Geir-Magnus Pettersen mentioned!
- Chris PoteetCopper Contributor
Kerem Yuceturk Here is an edit to update multiple sites.
https://www.siolon.com/blog/update-multiple-sharepoint-online-sites-to-search-whole-tenant/
- Kerem YuceturkMicrosoftThat's great! Thank you for sharing!