Sunday, 29 April 2007

SharePoint 2007 - Creating custom search scopes

By default SharePoint sites comes with a number of search scopes:

  • People
  • All Sites

besides the implicit search scopes which change according to the context:

  • This Site
  • This List

You can however create your own search scopes, to be able to filter your search results according to a number of rules. All this functionality is available out of the box and using the administration interface, and that gives you lots of flexibility and customisation.

Creating New Search Scopes

You can create your search scopes from the SharedServicesProvider:

SharedServices > Search Settings > Scopes (Click on the default scopes to add your own scope).

Give your new scope a name (e.g. you just want to search in Document Libraries). Once you have created the scope, you need to Add Scope Rules for this scope.

There are once again various rule types you can use:

  • Web Address (URL / Hostname / Domain / Sub-domain) - in our example here you add the specific urls of each document library that you want to target with your search scope

  • Property Query (here we can define scope rules based on Property Mappings in indexed items. e.g. Author, FileExtension etc. If you don't find the property you are looking for, you need to go to Search Settings > Managed Properties click on the specific property (e.g. FileExtension) and click on "Allow this property to be used in scopes". The property will then be available when defining new rules using the Property Query. If you only want to find Excel files using this scope using FileExtension = xls

  • Content Source (You can choose which content sources are available for this scope. A good example when to user this is if you want to create a search scope for a network drive you have indexed)

For each of the above you can also specify the behaviour of each rule i.e. whether to include / require / exclude the rule E.g. you can choose to exclude files written by a particular author.

Once you have defined all the rules for your new search scope you need to perform a full crawl of your Content Sources, and then perform an update of the Search Scopes. These functions can all be done from the Search Settings page of the SharedServices Provider.

Once this is done, you need to enable the Search Scope (either for the Search Dropdown, or for the Advanced Search or both) in the Search Scope settings of your Site Collection (this is done from the actual frontend not from the Central Administration). In the Site Settings > Search Scopes you click on the display group you want, and set the order that the scope should be visible.

As you can see, the scopes are quite a powerful tool in your arsenal. What I like about this is that instead of having just a top-down search scope (as per default scopes), you can have a scope which is across sites, but limited to certain parts only.