editing what is available to be searched within my sharepoint collection

RCDA Webmaster 291 Reputation points
2020-10-15T18:15:19.317+00:00

I have a SharePoint online site collection with a number of sub sites. I want to be able to prevent several of the sub sites from being returned by the search center results. Is there a way to tell SharePoint not to include specific sub sites? Do i do that under the individual sites or in the search center. I'm kind of new to search and have not done much with it since my company had the 2007 on premises site.

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Allen Xu_MSFT 13,866 Reputation points
    2020-10-16T06:29:18.687+00:00

    Hi @RCDA Webmaster

    Here are some solutions for you to meet your needs.

    1) To use Search and Offline Availability Setting:

    *Go to the subsite to be excluded from the search result;
    *Click on "Search and offline availability" under Search group in Site settings page;
    *Choose "No" for Allow this site to appear in search results option;
    *Click on "OK" to save your changes.
    32779-1016-1.png

    2) To use PowellShell:

    #Load SharePoint Online Assemblies  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
    
    #Variables for Processing  
    $SiteUrl = "https://XXXXX.sharepoint.com/sites/XXXXX"  
    
    #Get Credentials to connect  
    $Cred= Get-Credential  
    
    Try {     
        #Setup the context  
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)  
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
    
        #Get the Web  
        $Web = $Ctx.Web  
        $Ctx.Load($Web)  
        $Ctx.ExecuteQuery()  
    
        If($Web.NoCrawl)  
        {  
            Write-host -f Yellow "Site is Already excluded from Search Index!"  
        }  
        Else  
        {  
            #Exclude Site from Search  
            $Web.NoCrawl = $True  
            $Web.Update()  
            $Ctx.ExecuteQuery()  
            Write-host -f Green "Site is Excluded from Search Index Successfully!"  
        }  
    }  
    catch {  
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red  
    }  
    

    We can also use PnP PowerShell to exclude a site from SharePoint Online search index:

    #Parameter  
    $SiteURL= "https://XXXXX.sharepoint.com/sites/XXXXX"  
    
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
    
    #Exclude Root Web of the Site Collection from Search Index  
    $Web = Get-PnPWeb  
    $Web.NoCrawl = $true  
    $Web.Update()  
    Invoke-PnPQuery  
    

    Note: Please update the variable $SiteURL with your SharePoint Online environment(the subsite to be excluded from the search result).

    3) To use Query Rules:

    *Navigate to your search center;
    *Go to Search Results page by entering some search query and clicking on search;
    *Once You are in Search results page (Pages/results.aspx), Click on Settings gear >> choose "Edit Page";
    *Locate "Search Results" web part, and choose "Edit this web part" from its context menu. This opens the web part properties pane;
    *In the Web part properties panel, Click on "Change Query" button. You'll get a Popup page to build your query;
    *In the "Build your query" dialogue window, select "Path" in the property filter dropdown. Change the parameter to "Not starts with". For the value, select "Manual value" and then type the URL for the site you want to exclude and then click the button "Add property filter". This appends the "Query Text" box with “-Path:https://site-to-remove/”.
    32814-1016-5.png

    Save, Check-In and Publish the page! If you want to exclude multiple subsites, use OR operator. E.g. {searchboxquery} -Path:https://XXXXX.sharepoint.com/sites/XXXX1 OR -Path:https://XXXXX.sharepoint.com/sites/XXXX2.

    4) To use Remove Search Results:

    Go to search administration in SharePoint admin center -> Remove Search Results:
    32826-1016-6.jpg

    Type the subsite URL you want to exclude from search results into text box -> Remove Now:
    32827-1016-7.jpg

    This method may take some time to work, please be patient for a while.

    I hope this information has been useful, please let me know if you still need assistance.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.

    0 comments No comments

  2. RCDA Webmaster 291 Reputation points
    2020-10-16T13:42:54.597+00:00

    Thanks. I was able to set each sub site's availability to be part of the search results without issue. It then got me thinking.

    Rather than restrict from search... sub sites with sensitive information should be returned only for site users who have permission to access the sub site. After a bit of research, That is how search was setup OOTB.

    Now I need to get the search center to give me quality results. What I mean is:

    I searched for the word "Pension". It's the name of a document library on the HR site. The results were less than desirable. Each of the four documents in the library were listed multiple times and the library was listed after them. I'd rather see library listed first, then document results each item being listed only once.

    I'm trying to figure out why a single file would be listed 3 times, or 2 times instead of just once. Could it be that it's due to versioning?

    32927-image1.jpg

    0 comments No comments

  3. RCDA Webmaster 291 Reputation points
    2020-10-16T15:01:29.087+00:00

    I tried to add a search box to the homepage of the site and although the web part was added to the page, the web part is blank. I've tried searching the internet for an explanation and can't find anything. I did try setting the height and width of the webpart, but that just added more blank space to the page. I can't think it would be an error with the webpart since it's in the 365 cloud.

    What am I missing?

    0 comments No comments

  4. Allen Xu_MSFT 13,866 Reputation points
    2020-10-19T10:18:31.563+00:00

    @RCDA Webmaster ,
    1.For your issue the same file appeared in search results multiple times:

    I have tested in my environment and I created a major version and several minor versions for my file, but I can search it with one result returned.

    If you don't want the multiple duplicate search results, I suggest you to verify the following two settings:

    1)Uncheck “Show View Duplicates link” Setting:

    Go to Edit Web Part -> Settings -> Uncheck Show View Duplicates link:
    33372-4.png

    2)Remove duplicates:

    Go to Edit Web part -> change query -> Settings -> Remove duplicates:
    33260-5.png

    2.For your issue you added a search box to the homepage and it was shown as a blank zone:

    The search box you added to is a OOTB web part or customized by yourself?

    I also suggest you to check whether the web part is opening on your page.

    Go to your homepage -> add “?contents=1” to the end of URL:
    33278-6.png

    Check whether the “open on page” section of Search Box is set to “Yes”:
    33353-7.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.

    0 comments No comments

  5. RCDA Webmaster 291 Reputation points
    2020-10-21T20:30:33.92+00:00

    I figured out why the search area is blank. Someone, AKA: me, set the search area to display:none. Back in the day, we didn't need a search box so I set it to not display rather than remove it and not be able to get it back..

    I've removed that from the alternative CSS file and the search box appears on the site to the right of the global navigation bar as was intended. The problem now is that the box is 99 percent off the right of the screen and without scrolling, can get missed.

    Without scrolling right:
    34171-image1.jpg

    Scrolling right:
    34172-inage2.jpg

    I tried editing the masterpage and moving the box to a better location on the site; above the left side menu bar. That worked until I started clicking around and that found for one of the sub sites, the form pages for web parts place the search box still to the right of the global nav bar. Everywhere else the box moves as per the masterpage. It's as if the site is using modern masterpages rather than classic.

    can someone help me figure this out?

    ----------


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.