SOLVED

Configure modern search results to search all of your organization (rather than the current site)

Microsoft

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. 

Searching in a site will show results from that site (Strategy and Planning), with a control to expand the search scope to the hub (Sales) or the whole organizationSearching in a site will show results from that site (Strategy and Planning), with a control to expand the search scope to the hub (Sales) or the whole 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.After the change, results from the whole organization are displayed.After the change, results from the whole organization are displayed.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.

77 Replies

@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.

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.

@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.

@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.  

@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
 

@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?

@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.

 

@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.

@Kerem Yuceturk 

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. 

 

GaryRaboen079_0-1611319905389.png

 

What am I doing wrong, or is it some other setting that needs to be changed?

 

@Kerem Yuceturk 

 

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.

@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

A bigger issue here is being able to exclude sites from tenant wide searching without disabling search on them. We have users that want their site to be searchable to them when they are on the site but don’t want people finding results on it from the Intranet which is scoped to use tenant wide searching. Currently there is no solution for this and especially when the site has lists where all users can create new items, this means they are all visible through the search to everyone.

@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?

is there the ability to set a scope to search a couple of hubs? Our intranet is the main hub but we have 2 others that we'd like the following to happen:
Intranet hub - search hub and the other 2
the other 2 just search within their own hub.

Can someone confirm they get similar outcomes to what I describe here?
I'm working with an agency in a large multi-tenant organisation. When end-users search from a SPO site with'Search this site', the search URL contains /siteall?q=queryword and the search returns from other sites in the tenancy that the user appears to have access to. This is confusing when they only searched 'this site'.
I understand this to mean that the SearchScope is set to '1' (Tenant). Is this now the default setting for all sites (is 0, the default behaviour, actually '1'?)
Clicking on 'Organisation' doesn't change the search results (still includes other sites in the tenancy) but the search URL no longer has the /siteall element.
Am I right in saying the only way to fix this (to restrict search results to just that site) is to run the PnP script and change the SearchScope to '3'?
Thanks in advance.

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

What 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).