Orphaned "Related Sites" Scope in Searchbox dropdown


  

I have seen a couple of cases where then end users where having an issue with the "Related Sites" search scope within a SharePoint Portal Site. By default, when you create a Collaboration Portal, the following 3 Search Scopes show up when you first load the page:

This Site: Home
All Sites
People
  

These are the 3 main scopes that get pulled in from the SSP within a SharePoint farm. "This Site" would be considered a Contextual Scope and is specific to searching for content only within the context of that site. If you were to browse to the "Related Links scope settings" within a site and add an addtional search scope, based on another URL, like http://microsoft.com, and then re-compile your scopes manually or let the SSP scope compilation complete automatically (every 15 minutes by default). When you go back to the home page your site, you should see a "Related Sites" search scope in the drop down. This is all good if you intend to utilize this search scope, but the issue comes to surface when you decide that you no longer want to have any "Related Sites" search scopes within that site.  So lets say you perform the following actions to remove the related links:

  

At this point you would expect the "Related Sites" to disappear, so you browse back to the /_layouts/RelLinksScopeSettings.aspx page and see the words "emptytext" in the "Available Links"section of the page. This gives the impression that a scope exists in the site so this is why the "Related Sites" scope is still present in the search drop down.

So you ask, how can I get rid of this at this time? It is not really causing any real problem other than maybe some confusion for the end users who are trying to search for information within this site. While there is not a direct way through the UI to remove this from the search scopes, I can provide you some sample Object Model code that you or a developer can compile and run against the site URL and get that to disappear from the drop down. Again this is Sample Code and has no warranty and is not supported by Microsoft. This code will basically identify the WebID within the content database for the site URL you want to remove the "related sites" link from and then correleate that GUID with the Scopes in the SSP DB and delete the item from the database. After this is completed, it is necessary to go ahead and update the scopes and then do an IISReset in order to flush the compiled pages from memory. Below is the Sample Code you can use to remove the "Related Sites" scope from a site"

 =======================================================================

 

Sample Code

·         We basically created a Form Box for the GUI 

·         Then compile the code below:

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Collections;

using Microsoft.SharePoint;

using Microsoft.Office.Server;

using Microsoft.Office.Server.Administration;

using Microsoft.Office.Server.Search;

using Microsoft.Office.Server.Search.Administration;

    

namespace scopedelete

{

     public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

         private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text.Trim() == "")

            {

                MessageBox.Show("Please enter the root web URL.");

            }

            else

            {

                SPSite site = new SPSite(textBox1.Text);

                SPWeb myweb = site.OpenWeb();

                Guid mywebid = myweb.ID;

 

              //  MessageBox.Show("webid : " + mywebid.ToString());

 

                Uri siteuri = new Uri(site.Url);

                Microsoft.Office.Server.ServerContext myservercontext = Microsoft.Office.Server.ServerContext.GetContext("SSP");

                SearchContext scontext = SearchContext.GetContext(myservercontext);

                Scopes sspscopes = new Scopes(scontext);

 

                ScopeCollection allscopes = sspscopes.AllScopes;

                Scope myscope = null;

                Scope MydeleteScope = null;

               

                IEnumerator myscopeenum = sspscopes.AllScopes.GetEnumerator();              

 

                for (int i = 0; i < allscopes.Count; i++)

                {

                    while (myscopeenum.MoveNext())

                    {

                        myscope = (Scope)myscopeenum.Current;

                      //  MessageBox.Show(myscope.Name); 

                        if (myscope.Name == mywebid.ToString())

                        {

                            MydeleteScope = myscope;

                            break;

                        }                       

                    }

                }

                if (MydeleteScope == null)

                {

                    MessageBox.Show("Related sites scope for site " + myweb.Name + "(" + textBox1.Text + " ) does not exist.");

 

                }

                else

                {

                    MydeleteScope.Delete();

                    MessageBox.Show("Related sites scope for site " + myweb.Name + "( " + textBox1.Text + " ) deleted successfully");

                }

            }

        }

        private void Form1_Load(object sender, EventArgs e)

        { 

        } 

     }

   }

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                               

   ** Please note that where I have highlighted “SSP” you will need to replace that value with the name of your SSP 

' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF

' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO

' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A

' PARTICULAR PURPOSE.

' Please stress test this code before deploying it in a production environment.
' This is intended as a sample of how code might be written for a
' similar purpose. This code has not been tested.  This code is
' also not to be considered best practices or prescriptive guidance. 
 
' It is highly recommended that you FULLY understand what this code is doing
' and use this code at your own risk.

' Copyright (C) Microsoft Corporation, 2009 

  

·         Once this is compiled and executed browse to your SSP Admin Site

·         Click on Search Settings:

·         Find the Scopes Section and click on “Start Update Now”

·         Once that has been updated go into your WFE server(s) and recycle the application pools for the Web App you just executed this against.

  

After the page has been rendered again, you should see that the “Related Sites” option is no longer present in the Search Drop Down Box

 

=======================================================================  

  

To confirm that the scope has been deleted, you can open up SQL Server Management Studio and then run the following queries to see that the GUID for that scope has been removed from the SSP Database.

  

  • First you would need to get the WebId from the content DB that you ran the code against
  • Open SQL Server Management Studio and create a New Query
  • In the drop down, next to the "execute" function in the toolbar, make sure you have the Content Database select
  • Then run the following:

          select * from Webs

 

  • Identify the Id where root of that site exists.
  • Copy this GUID and put it into notepad
  • Then create a new query and this time make sure the SSP DB is selected, not the Search DB, but the SSP DB
  • Then run the following:

          select * from MSSScopes

  • If the GUID is still present in that table, then you have not successfully removed the scope. If it is no longer present, then the "Related Sites" scope should no longer be there when the Scopes are Updated and IIS has been reset.

  

 I hope this helps in the event you want to get rid of that "Related Sites" scope within your Search Drop Down!

Comments (0)

Skip to main content