DarioSantarelli.Blog(this);

MOSS 2007: Programmatically Configure Search Scopes

Posted by dariosantarelli on April 20, 2007

In the code below you can find a way to use the MOSS 2007 Administration Object Model to programmatically create a search scope in your Shared Service Provider and include your content sources to the created search scope.
Hope it helps… 😉

using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;



SearchContext context;
using (SPSite site = new SPSite(“http://<SSPsite>&#8221;))
{
context = SearchContext.GetContext(site);
}
Schema sspSchema =
new Schema(context);
ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
Scopes scopes =
new Scopes(context);
ScopeCollection sspScopes = scopes.AllScopes;
Scope newScope = sspScopes.Create(“Name”, “Description”,
null, // System.Uri object representing the owning site URL
true, // True to display the scope in the SSP Administrator UI
null, // A string specifying the alternate results page for the scope
ScopeCompilationType.AlwaysCompile);
// Includes your content sources to the created Scope
foreach (string ContentSourceName in YourContentSourcesNames)
{
newScope.Rules.CreatePropertyQueryRule(ScopeRuleFilterBehavior.Include,
properties[“ContentSource”], // Managed Property
ContentSourceName);
}
// Update Scopes
scopes.StartCompilation();
Advertisements

2 Responses to “MOSS 2007: Programmatically Configure Search Scopes”

  1. Dennis said

    Thanks a lot for this post. I was looking for some similar code and this seems very useful.

  2. Byron said

    Awesome! You’ve just given me a minimum of 4 different ideas to write about on my web site. It’s much like yours, just not as big.
    It’s actually a subniche truth be told.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: