views:

656

answers:

1

Hello, I'm trying to use FullTextSqlQuery in to find a list of sharepoint sites a user has access to. Here's my code:

SPFarm farm = SPFarm.Local;

SPWebServiceCollection webServices =
    new SPWebServiceCollection(farm);

foreach (SPWebService webService in webServices)
{
    foreach (SPWebApplication webApp in webService.WebApplications)
    {
        using (FullTextSqlQuery fullTextSqlQuery = new
            FullTextSqlQuery(ServerContext.GetContext(webApp)))
        {
        // Do some Initializtion
        fullTextSqlQuery.QueryText = 
            "select title, path from scope() where (contentclass = 'STS_Web' or contentclass = 'STS_Site') order by path";

           // execute the query and gather results
        }
    }
}

I naturally thought the search scope of an FullTextSqlQuery is defined by the argument of the constructor, as a web application would be the search scope in this case:
FullTextSqlQuery fullTextSqlQuery = new FullTextSqlQuery(ServerContext.GetContext(webApp))

However, for each web application, the query returns exactly the same result, which means webApp is not used as a scope. So where how I define a scope for a query?

Thanks.

+1  A: 

The scopes are defined (either out of the box or custom) in the Shared Service Provider your web app is using. In the site collection settings of yoru site you can further specify allowed and used scopes.

The Shared Service Provider is found in the Central Admin's left menu, then, once in the ssp admin site, you can add, modify and delete Search Scopes.

More info here.

Colin
Hello Colin, thanks for you answer. I'm new to Sharepoint. In my case, I initialize queries from different web apps, but the queries all return the same result. Does that mean those web apps use the same SSP?
Bryan
Yes it does. YOu can create new SSP's if needed, or just define scopes within a single SSP
Colin
Thank you Colin.
Bryan
So what does the context or SPSite parameter in the constructor actually do if it doesn't set the scope?
Rob Volk
It serves as an entry point to the webapp (i think). A webapp is either not a part of an SSP at all, or 1 specific SSP.(if 0, it is not included in any ssp, which effectively disables office search for that webapp, and a webapp can be part of 1 SSP only)
Colin