Share via


Creating and Exposing Search Scopes in SharePoint Server 2007 Enterprise Search

Summary:  Learn how to create and expose search scopes in Microsoft Office SharePoint Server 2007 Enterprise Search.

Office Visual How To

Applies to:  Microsoft Office SharePoint Server 2007

Patrick Tisseghem, U2U

April 2007

Overview

Search scopes in SharePoint Server 2007 are used to narrow the search results returned to users executing a search query. Search scopes can be shared or locally defined. You can use different rules in the definition of a search scope, from simply scoping based on a content source to more complex scoping with conditions using custom metadata. You can view search scopes in the browser with scope pickers. Scope pickers are connected to a display group listing the scopes to be displayed.

Code It

Administrators can create search scopes in the browser but Office SharePoint Server 2007 exposes a new search administration object model. The code samples in this article show the steps to create a shared search scope and deliver it as part of the search experience on a collaboration portal.

You must execute the sample code on a server running Microsoft Office SharePoint Server 2007. Also, the code requires references to the following files:

  • Microsoft.SharePoint.dll

  • Microsoft.Office.Server.dll,

  • Microsoft.Office.Server.Search.dll

  • System.Web.dll

The following namespaces are used:

Connecting to Shared Services Provider and the Search Context

It is important to understand how to add references to the Shared Services Provider and the Search Service. This understanding is essential before beginning work with search scopes. The following code sample uses the name "SharedServices1" as an example Shared Services Provider.

Listing Existing Search Scopes

List shared search scopes by instantiating an object of the Scopes class using a reference to the SearchContext as argument in the constructor. Next, the GetSharedScopes class is used in a loop over all of the scopes.

Retrieving Information about the Rules

Rules determine the search scope, and you can retrieve all the rules with their details. The following code example shows the three different types of rules available in the object model.

Creating a Shared Search Scope

Create a shared search scope by adding a new Scope instance to the ScopeCollection. The ScopeCollection is exposed as the AllScopes property at the level of the Scopes instance. After you create the shared search scope, use the CreateUrlRule method to associate one or more rules to the scope.

Compiling Shared Search Scopes

You need to compile search scopes before you can use them. This involves flagging items that match the scope rules in the physical index file. The compilation starts at the level of the Scopes instance.

Listing Display Groups

Search scopes are visualized in scope pickers on SharePoint sites. A scope picker displays the scopes listed in one of the display groups. The following code retrieves all display groups for a specific site collection:

Associating a Shared Search Scope with a Display Group

You must add a search scope to the display group for the scope picker to show it.

Read It

Search scopes narrow the search results for users. You can define them at two levels within a SharePoint Server 2007 environment:

  • You can create shared search scopes at the level of the Shared Services Provider. You can use them in all site collections within your server farm that are hosted on a Microsoft Internet Information Services (IIS) Web Application bound to that Shared Services Provider.

  • You can also create local search scopes at the level of the individual site collection. These scopes cannot be re-used in other site collections.

A search scope is defined by one or more rules. Microsoft Office SharePoint Server 2007 introduces new types of rules to guide the search scopes exposed by different types in the object model:

  • The AllContentScopeRule class represents a scope rule that includes all items in the index.

  • You can use the PropertyQueryScopeRule class to create a scope rule that matches content items based on a property to value comparison

  • The UrlScopeRule class represents a scope rule that matches content items based on the display URL of the item.

You must compile search scopes before using them. To compile search scopes, you flag each item in the index that matches the rules as they are defined for the search scope.

After updating your scopes, you can view them by including them in a display group that is connected to one or more of the scope pickers in the user interface. A scope picker is a drop-down list that is used by an end-user to select either specific search scopes or contextual search scopes such as the "Search This Site" scope.

See It Presentation Opening Slide

Watch the Video

Length: 10:28 | Size: 9.31 MB | Type: WMV file

Explore It