Apr 12 2019 11:32 AM - edited Apr 08 2020 04:49 PM
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.
Feb 25 2020 06:13 AM
@Kerem Yuceturk While you are working on it. I'd like to vote that it works by giving people an option to search all sites in the hub or just the existing site. :) Thanks for the update.
Apr 08 2020 04:43 PM
Hi @Colleen Parker, and all,
I'm happy to report that you can now search across all sites in the hub that the current site is associated with by default. I've also updated the main post at the top of the thread.
To do this, set the SearchScope value to 2.
Hope this helps with your scenarios!
We are also working on adding a dropdown into the search box that the user can use to choose where to search. We hope to release this in a few months.
Apr 08 2020 05:32 PM - edited Apr 08 2020 05:43 PM
@Kerem Yuceturk This is great, my site managers will be thrilled! Where do I set that Search Scope setting? Is that a site collection setting?
I went into the Manage Result Sources and saw this message.
Result Sources replace Search Scopes, which are now deprecated. You can still view your old scopes and use them in queries, but not edit them.
I'm not a SharePoint Search expert, so I'm likely overlooking something obvious.
Apr 09 2020 07:31 AM
@Colleen Parker, sorry about the confusion. Please refer to the original message at the beginning of this discussion thread. I've updated this to include instructions for the hub scoped search as well. The instructions work using PowerShell. Currently we don't have a user interface button for setting this, but we are planning on adding user interface controls in a future release.
Search Scopes reference you saw above refers to some of our pre-2013 classic search experiences.
Apr 20 2020 01:46 AM
@Kerem Yuceturk I am new to Powershell. I have manage to login on SPO. But I am getting an error using the first commando ($web = Get-PnPWeb) see beneath. Can you guys and girls help me?
Get-PnPWeb : The term 'Get-PnPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:8
+ $web = Get-PnPWeb
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-PnPWeb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
May 14 2020 03:06 AM
Aug 19 2020 03:29 PM
@Kerem Yuceturk - We have unique situation. Our intranet site site just have landing page and links to all hubs (Company, My HR, Reference Library) in top navigation. The reason we have this set up as we can't have more than one level of hub (nested hub). How can we update search behavior so it will search only on root site for our intranet and multiple sites\hubs (Company, My HR, Reference library in our case)?
In our old intranet site (based on publishing portal), we had created custom search scope to restrict search into specific sites. How can we achieve similar behavior in modern communication sites?
Sep 09 2020 01:09 PM
@Kerem Yuceturk , Is there a way to Remove"Organization" scope link? We would like to limit users to only search within hub and hub sites, not to show "organization" at all.
Jan 13 2021 03:16 AM
@Kerem Yuceturk
A step in the right direction but still very limited and short-sighted. But we need even more flexibility than this.
We also need to be able to define explicitly certain sites or multiple hubs.
For example, an organisation has built an intranet which is comprised of several hubs. We need to be able to set the search scope to "the intranet" and therefore be able to specify multiple hubs.
Also, for example by wildcard in URL's. If we have defined a naming convention with a prefix, for let's say projects. All project sites have the prefix 'proj-'. We need the search scope to be able to be defined for "all project sites".
Honestly, the scenarios are pretty much endless.
Jan 22 2021 04:53 AM
I've just completed this task in Powershell, see below, but when I'm on the landing page and search for the site, the extra click to search the whole organization is still needed. Not a single command has come with an error whatsoever.
What am I doing wrong, or is it some other setting that needs to be changed?
Feb 09 2021 02:59 AM
Please let me know how to configure the search from certain site hubs and not from the entire organisation? I have a requirement and I am looking to configure the search from a few site hubs only.
Feb 09 2021 05:17 AM
@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
Mar 23 2021 10:54 AM
Apr 07 2021 12:19 AM
@Kerem Yuceturk what's the difference between SearchScope = 0 and SearchScope = 3?
Is there a global setting which determines the search scope so I can change it globally?
Oct 05 2021 10:50 AM
Jan 13 2022 04:18 PM
Mar 04 2022 06:43 AM - edited Mar 04 2022 06:46 AM
Hi Martin - I also would love the same structure of searching just the site content but allow for searching people. Did you ever find a way? ty
Mar 04 2022 06:57 AM