MOSS gives site admins the tools to target searches to users' needs
| Executive Summary:|
Microsoft Office SharePoint Server (MOSS) 2007 includes the Advanced Search Web part and the Search Center site template so SharePoint site administrators can take control of the search environment. You can set targeted search scopes, and provide custom search forms and results pages.
Search capabilities in Microsoft Office SharePoint Server (MOSS) 2007 include a host of powerful features suitable for a large enterprise intranet or extranet. Although Windows SharePoint Services (WSS) 3.0 also includes many of these features, only MOSS provides the easy customization of the search scope and UI. SharePoint administrators can customize MOSS to meet many specific business needs.
With MOSS, you can search a wide array of sources in the network, such as Web sites, file shares, and Microsoft Exchange Server public folders—not to mention site contents within the SharePoint server itself. The MOSS standard site collection feature pack offers two search enhancements, an Advanced Search Web part and the Search Center site template, that Share- Point administrators can use to fully customize the site’s UI and search behavior. SharePoint offers two display options for search results: through a search Web service or through the built-in search results page. The search Web service, which lets you access results from client applications outside of the context of SharePoint, is development-intensive and beyond the scope of this article. Managing search scopes and accessing search results from within the SharePoint UI, however, doesn’t require a developer’s skill set—although it isn’t necessarily intuitive or straightforward.
Customize Search Scope
Because SharePoint can crawl contents from a wide array of sources, you use search scopes to let users search a specific subset of the workspace’s entire contents. Targeted scopes help you get better search results while boosting overall search performance.
You customize search scopes in MOSS in the Shared Services Administration section of SharePoint Central Administration. Shared Services are applications that run behind the scenes on their own Microsoft IIS Web applications. These services can be configured from a single place and shared for use by SharePoint sites on multiple MOSS and WSS servers— hence the name. The MOSS search engine is an example of Shared Services. Keep in mind that someone with administrative privileges in the regular SharePoint content sites won’t necessarily have access to Shared Services Administration.
By default, MOSS has two out-of-the-box search scopes:
- People—searches for all content in the My Sites area of the SharePoint farm.
- All Sites—searches for content in the entire SharePoint farm.
These scopes both cover a rather broad range of sites. You’ll have to create your own scopes to target more specific areas of your content. Take, for example, a document library list named Catalog, with various custom columns that track document metadata. In the default setup scenario, if you want to search for content only within this document library, you would have to navigate to that document library, then select This List: Catalog in the search scope drop-down menu.
The first item in the drop-down menu is specific to each page. If you’re somewhere else on the site, you’ll see different options on the list—but you won’t see the This List: Catalog scope. The solution is to add a new search scope that appears in the search scope list on every page. Here are the steps to follow to create the new scope:
- Navigate to the site’s Shared Services Administration home page.
- In the Search section, click Search settings.
- In the Scopes section, click View scopes.
- Click New Scope on the toolbar.
- On the Create Scope page, enter a title—this is the text that will appear in the search scope drop-down menu.
- In the Target Results Page section, select Specify a different page for searching this scope and specify a new page name, such as catalogresults.aspx. If the .aspx page you specify doesn’t exist yet, you can create it by accessing the Site Actions menu of the target SharePoint site. Click OK.
Now that you’ve created a new search scope, you need to specify the content this scope should query when searching by adding a rule for the search scope, as follows:
- On the View Scopes page, click the Add rules link for the search scope you just created.
- On the Add Scope Rule page, in the Scope Rule Type section, click Web Address.
- In the Web Address section, enter the path to the document library under Folder.
- In the Behavior section, select Include. Click OK.
You’ve now specified a content source for the custom search scope. The next step is to have SharePoint display this custom search scope in the search drop-down menu. This configuration is done through the SharePoint site’s Site Settings page:
- Navigate to the top-level SharePoint site home page
- Select Site Actions, Site Settings, Modify All Site Settings.
- Under Site Collection Administration, click Search scopes.
- Click the Search Dropdown link.
- On the Edit Scope Display Group page, select the scope you created earlier. As Figure 1 shows, you can also change the order of search scopes on the list and set the default search scope. Click OK.
Schedule the Search Crawl
The SharePoint search engine crawls the content in the search scope every so often. The frequency of this crawl is controlled by a search schedule. By default, SharePoint is set to crawl only once in a 24-hour period for the default search scope content. After you’ve defined your custom search scope, you need to set up a crawl schedule for it. You can set up separate schedules for full crawls, which build an index of all site content, and incremental crawls, which index only changes to content since the last crawl.
A full crawl takes longer and is more resource intensive on the server than a partial crawl. Therefore, it’s best to schedule fewer full crawls than incremental crawls and to schedule them during non-peak hours. A partial crawl, however, doesn’t detect all types of changes.
For example, when a row item on a Share- Point list is changed or deleted, a partial crawl won’t find the change because it can’t recognize changes to .aspx pages. A full crawl is required to re-index the list data after such changes.
You set up custom crawl schedules through the site’s Shared Services Administration. Follows these steps:
- Navigate to the Shared Services Administration home page and click Search settings.
- Click Content sources and crawl schedules under Crawl Settings.
- On the Manage Content Sources page, right-click the content source for which you want to schedule a crawl, then click Edit. You can also define a new content source by clicking the New Content Source button on the toolbar.
- On the Edit Content Source page, in the Crawl Schedules section, click the Create schedule link below either the Full Crawl or Incremental Crawl drop-down list.
- In the Manage Schedules dialog box, fill in the crawl schedule details and click OK. For example, to run the crawl every two hours throughout the day, select Daily in the Type section; under Settings, enter 1 in the Run every box so it runs every day; select the Repeat within the day check box, then enter 120 in Every as the number of minutes between crawls and 1440 in For as the number of minutes for this cycle to repeat.
Customize the Search UI
Adding a custom search scope to the search drop-down menu is an example of search UI customization. MOSS provides numerous out-of-the-box features, such as Web parts and site templates, that let you customize the UI of both search and results pages. Search Center is a new site template dedicated to search functionality; it’s embedded with many standard search-related Web parts.
The Search Center site template comes in two flavors: Search Center Lite and Search Center with Tabs. Search Center Lite is available in site collections by default where the Office SharePoint Server Publishing feature isn’t activated. Search Center with Tabs is available in site collections with the publishing feature activated; this version lets you create a custom UI that includes tabs with different searches. You can see a list of both activated and available features of a site by going to the site collection’s administration page and clicking Site collection features. The Search Center is usually a sub-site under the site collection with the URL http://
Continued on page 2
Customize Search Tabs
You use tabs to group search queries and results by scope. By keeping each scope in its own tab, you can also create a different search form for each scope. Users access a custom search form to query by fields or values that apply only to a particular scope, and the results displayed pertain only to that scope.
By default, the Search Center contains two tabs, All Sites and People. These tabs appear on the Search Center home page. The All Sites tab searches all SharePoint content sites; the scope for People is limited to My Sites. If you want to add a new custom tab, follow these steps:
- On the Search Center home page, click Site Actions, Edit Page to reveal the Web parts that form this search page.
- Click Add New Tab.
- Enter a tab name (e.g., Catalog) and page (e.g., catalog.aspx), then click OK.
- Click Site Actions, Create Page.
- Create a new .aspx page with the name you used in step 3 using the (Welcome Page) Advanced Search page layout template, then click Create.
- In the Middle Upper Left Zone (or a different zone if you prefer), click Add a Web Part.
- In the Add Web Parts dialog box, select Advanced Search Box, then click Add.
You’ve added a new search tab named Catalog to your Search Center, and it includes the Advanced Search Web part.
Customize Advanced Search
Earlier, we created a custom scope that you could access from anywhere in the site to search for contents only within the Catalog document library. Now, imagine this library has a custom column named Color Category. We want users to be able to search for documents in this library that are tagged with a particular color. With the standard search box, if the user searches for a color (e.g., green), the results include all documents that have the word green anywhere in the document body or metadata. But what if the user wanted to search only those documents that are tagged as green in the Color Category field? The Advanced Search Web part, with some customizations, can help answer that question. Here’s how:
- Go to the catalog.aspx page in Search Center, then click Site Actions, Edit Page.
- In the Advanced Search Web part, click edit, Modify Shared Web Part.
- The Advanced Search Web part tool pane appears on the right. This pane lets you customize most of the search behavior and text labels. The tool pane contains the following categories:
Search box. This category lets you show or hide text boxes for specific searches, such as “All words,” “none of these words,” and so forth. You can also change the label that appears with these text boxes.
Scopes. Here you can specify whether you want the scope selector shown to the user. When shown, the scope selector appears as a check box list so that the user can select more than one scope for a search. You can also specify which scope grouping to show in this list. Scope groups are defined on the Site Settings page under Site Collection Administration. The default groups available are Search Dropdown and Advanced Search. The Show the result type picker option lets users specify search result item types, such as Microsoft Word, Microsoft Excel, PDF, or HTML files; this option must be checked to enable the properties search.
Properties. This is where you can enable searches by custom fields. The Properties text box contains an XML code snippet that dictates how the properties are displayed in the search form.
Miscellaneous. This section lets you specify the results display page. By default, results are displayed in results.aspx, but you can create your own customized results page and enter its location here.
- Expand the Properties category in the tool pane to update the XML snippet to include the custom Color Category field. Click the ellipsis next to the text box to view the XML code.
- Locate the PropertyDefs> node and add the following code anywhere in it:PropertyDef Name=”ColorCategory”
- Locate the ResultTypes> node with the DisplayName="All Results" attribute and add the following anywhere in it:
PropertyRef Name=”ColorCategory” />
- Click OK to save changes. As Figure 3 shows, when you refresh the search page, you’ll see a new value named Color Category for property restrictions.
Manage Metadata Property Mappings
Note that in step 5 above, we referred to a property definition with the name ColorCategory. SharePoint doesn’t yet know how to search for this property. You need to define this property such that it maps to the field named Color Category in the Catalog document library. This definition is done through metadata property mapping. SharePoint list and document library fields are also referred to as properties. As the SharePoint search engine crawls through lists, it indexes the properties, which are then referred to as crawled properties. You define relationships between list properties and crawled properties through Search Setting’s Metadata Property Mappings. For the example above, you can define a new managed property named ColorCategory and map it to the crawled property that points to the document library’s field named Color Category by following these steps:
- Navigate to the Shared Services Administration home page and click Search settings.
- In the Crawl Settings section, click Metadata property mappings.
- Click New Managed Property in the toolbar.
- Enter ColorCategory for Property name.
- Make sure Text is selected under The type of information in this property.
- In the Mappings to crawled properties section, click Add Mapping.
- In the Crawled property selection dialog box, select the property labeled ows_Color_ x0020_Category(Text), then click OK. Note that all custom fields in lists and document libraries are prefixed with ows_ in the crawled properties index. Spaces in field names are translated to _x0020_.
- Click OK to save the property. You’ve now created a property definition that maps to the Color Category field. After a full crawl of the site, you can start using this property definition in the advanced search page to get targeted results.
Continued on page 3
Customize Search Results
By default, the Search Center displays results in the results.aspx page. You can customize this page or create your own results page. For example, consider the document library with the custom Color Category field. When a user searches against the Catalog scope, you want the search results page to display a field named Color Category. You can achieve this by modifying the XSL markup of the Search Core Results Web part in the search results page.
Start by performing a search with the Catalog scope so that you get a results page where only items that fall within the Catalog scope are displayed. After you have such a page, follow these steps to create a new search results page:
- Click Site Actions, Create Page.
- Enter a Title (e.g., Catalog Results) and a URL Name (e.g., catalogresults.aspx) for the new page.
- Select the (Welcome Page) Search Results Page layout, then click Create.
After step 3, you’ll see the catalogresults.aspx page in edit mode, which shows its various Web parts. Search Core Results is the Web part that displays the search results. You need to modify this Web part to include the Color Category column in the search results view. In the Search Core Results Web part, click edit, Modify Shared Web Part. This action displays the Web part properties tool pane. As Figure 4 shows, the tool pane contains the following categories:
Results Display/Views—In this section, you specify search results to display per page, sentences to show in the results display, and so forth.
Results Query Options—This section lets you specify options such as duplicate results removal, search term stemming, and noise word inclusion. Word stemming matches a search word with its grammatical variants; for example, the word crawl stems to crawls, crawled, crawler, and so forth. Noise words, also known as stop words, are words that aren’t significant indicators for content, such as the word the.
Fixed Keyword Query—This section lets you enter a specific keyword to automatically include with every search
Miscellaneous—Here you can narrow the scope of search results, and also choose options such as Show Action Links, Display “Alert Me” Link, Display “RSS” Link, and so forth.
Below these categories, you’ll find the Data View Properties section, which contains the XSL markup that controls the HTML to render the search results dataset. So, to continue the process of customizing the results page:
- Expand the Results Query Options category.
- Add the following line of XML to the Columns node in the Selected Columns text box, then click OK:
Column Name=”ColorCategory”/>Remember that we’ve already defined the ColorCategory column. The SharePoint search engine returns data internally in XML format. This XML data is transformed to an HTML view through XSL markup.
- Under the Data View Properties section, click XSL Editor to display the Text Entry dialog box with the XSL markup that renders the XML results into HTML.
- Copy the XSL markup to an external text editor, such as Microsoft Office Share- Point Designer 2007. SharePoint Designer is a WYSIWYG editor, so it helps you visualize the results of the XSL code as you edit.
- Locate the result template node in the markup; its first line looks like this:
- Add the following before the line
in the result template node:Note that the value colorcategory is written in all lower case, regardless of how it was written in metadata property mapping.Color Category: xsl:value-of
- Copy and paste the entire XSL markup back into the Text Entry dialog box, then click Save.
- Click OK to save changes to the XSL markup and the Web part.
Now when you perform a search using the search box, you’ll see the Color Category property exposed in the search results area. By following these steps, you can expose any property that’s already stored in the metadata
Control SharePoint Searches
You should now have a good idea of how you can customize the search experience in MOSS 2007. The procedures shown in this article, though simple, can easily be leveraged to create more meaningful business solutions that can crawl and index a large amount of disparate data, yet offer end users targeted search capabilities to zero in on a specific subset of data. Custom search scope definitions also let administrators schedule indexing and crawling of each scope separately: Only scopes with frequently changing contents need to be crawled frequently. This ability not only saves server resources, but it also makes the search results more accurate and fresh.