Search scopes are a slightly confusing concept in
SharePoint, as Microsoft has adopted the term "scope" to refer to a
structure categorization of documents based on filtering of documents on
their shared properties. It is best to think of search scopes as groups
of documents that have shared properties.
When setting up the
crawler, it is possible to create scopes based on managed properties.
This will allow pre-determined filter sets to be applied on new search
tabs and in search box drop-downs (must be enabled in the Site
Collection Search settings). Care should be taken to create scopes that
match business needs and possible future sectioning of the content. Any
managed property can be made available for scopes, but properties must
be explicitly defined as available for scopes in the Edit Managed
Property page.
To create a new scope,
navigate to the Scopes menu item under Queries and Results on the Search
Service Application page. On the Scopes page, the existing scopes can
be seen. In SharePoint 2010, there should be two default scopes, People
and All Sites, as shown in Figure 1.
1. Adding or Editing Scopes
A scope can be edited by
clicking it. Alternatively a new scope can be created by clicking New
Scope. This will open the Create Scope page, where the scope can be
given a name and description and a target result page set if the default
search center is not being used for that particular scope. No rules for
the scope will be applied on this page. This is done in the next step.
After the new scope is created, the site will return to the View Scopes
page. Here the new entry will appear with a link to add rules. If the
Add Rules link is clicked, a new page where rules for that scope can be
applied will appear.
There are four kinds of scope rule types:
Web Address:
Content can be delimited based on the URL of the site the content was
found under. This rule type is based on the protocol and URL of the site
(e.g., http://server/path). This rule can be applied on a folder, a hostname, a domain, or subdomain. Each setting has a unique field to apply the rule.
Property Query:
A scope rule can be created that filters documents based on common
properties across documents. For example, a particular content type or
author property can be used to isolate documents in a scope. The
Property Query option gives a drop-down of all managed properties that
have been set as available for use in scopes. The operator is always
equal so the value placed in the field must be an exact match to the
value in the property.
Content Source:
A scope can limit the result set to a particular content source.
Choosing Content Source will give a drop-down menu of all the defined
content sources in the Search service application.
All Content: A scope can also be based on all content in the index. Choosing All Content will simply return all content in that scope.
In addition to these rules,
specific behaviors may be applied for each rule except All Content. The
available behaviors are Include, Require, and Exclude.
Include:
Items in this rule will be included in the results of this scope unless
they are excluded by another rule applied to the same scope.
Require:
If Require is chosen, the scope will not include items that do not
conform to this rule. That is, all items must match this rule regardless
of other rules.
Exclude: Items matching an exclude rule will not be added to the scope or included in the search result set of the scope.
Multiple rules may be applied for any given scope.
2. Scope Update Schedule
Scope updates, as a
rule, happen every 15 minutes if set to automatically refresh. If
necessary, these updates can be changed to be made manually. This is
done from the main page of the Search Service Application page under
Scope Update Schedule.
3. Setting Scopes with PowerShell
Scopes can also be
managed with PowerShell cmdlets. It is possible to add, remove, and edit
scopes with PowerShell as well as manage the rules associated with the
scopes.
The following PowerShell commands are available for managing scopes:
Get-SPEnterpriseSearchQueryScope
New-SPEnterpriseSearchQueryScope
Remove-SPEnterpriseSearchQueryScope
Set-SPEnterpriseSearchQueryScope
Additionally, scope rules can be added, removed, and set using the following PowerShell cmdlets:
Get-SPEnterpriseSearchQueryScopeRule
New-SPEnterpriseSearchQueryScopeRule
Remove-SPEnterpriseSearchQueryScopeRule
Set-SPEnterpriseSearchQueryScopeRule
In order to set a rule, the
scope's name must be passed as a parameter for the cmdlet for adjusting
the scope rule. This is because rules are unique to individual scopes.
For example, to create a scope called PDF and set that scope to include
only items of the PDF file type, open the SharePoint 2010 Management
Shell console and use the following PowerShell cmdlets:
Get-SPEnterpriseSearchServiceApplication | New-SPEnterpriseSearchQueryScope -name PDFs
-description "PDF documents only" -displayinadminui $true
This will create a new scope called PDFs. The DisplayInAdminUI parameter should be set to $true
(or 1) if the scope should appear in the Search service application's
Scopes page in Central Administration. Otherwise, set it to $false (or 0) to hide it.
After creating the new scope,
it should have some rules applied to it. To do this, the ID of the
scope is required. Otherwise, if creating a scope and adding rules to it
at the same time, a variable can be assigned to the New-SPEnterpriseSearchQueryScope command like this:
$NewScope = Get-SPEnterpriseSearchServiceApplication | New-SPEnterpriseSearchQueryScope
-name PDFs -description "PDF documents only" -displayinadminui $true
Just like on the Scopes
page in the Search service application in Central Administration, there
are four rule types you can set with New-SPEnterpriseSearchQueryScopeRule. Here are the rule types and example cmdlets.
Web Address: To create a web address rule in PowerShell, the cmdlet takes the URL value in the rule type parameter. The parameter URLScopeType
must also be set. The values that this parameter takes are Folder,
HostName, or Domain, just like in the Scopes page in Central
Administration. Finally a value for the parameter MatchingString must be set. This is the string of the web address you want to set. The cmdlet would look something like this:
New-SPEnterpriseSearchQueryScopeRule -ruletype Url -matchingstring
http://prosharepointsearch/demos -urlscoperuletype Folder -filterbehavior
Include -url http://prosharepointsearch -scope $NewScope
Property Query:
Creating a property query rule is probably the most common. This rule
type requires a name for the managed property that will be used and the
value that the managed property will check. It also needs a filter
behavior as in the Scopes page, a URL, and the specific scope to apply
it to and the search application.
New-SPEnterpriseSearchQueryScopeRule -ruletype PropertyQuery
-managedproperty filetype -propertyvalue pdf -filterbehavior Include -url
http://prosharepointsearch -scope $NewScope
Content Source:
There is no specific rule type value for content sources. This is
because content source is a managed property in SharePoint. To set the
scope by content source, use the PropertyQuery value in the rule type parameter and set the name of the content source as the value.
New-SPEnterpriseSearchQueryScopeRule -ruletype PropertyQuery -managedproperty
ContentSource -propertyvalue "Local SharePoint Sites" -filterbehavior Include
-url http://prosharepointsearch -scope $NewScope
All Content: The All Content scope rule is quite straightforward as it simply includes all content. Use the following cmdlet:
New-SPEnterpriseSearchQueryScopeRule -ruletype AllContent -url
http://prosharepointsearch. -scope $NewScope