Using Search to Aggregate Data

The search feature efficiently queries large sets of distributed information. If you must aggregate information across site collection boundaries, it is preferable to use search instead of a query. This is because the data can be distributed across multiple query servers and cached as the search engine indexes the content.

Using Office SharePoint Server Search

An example of when to use search is in the Partner Portal application. It uses search to aggregate information about outstanding tasks. Contoso employees who work with partners to resolve issues must be able to view all the open tasks that are associated with the incident sites. These tasks are distributed across multiple site collections. The number of tasks and partner site collections varies as partners are added and removed. Potentially, this number can be very large.

The search feature aggregates data across an entire server farm. It includes two classes for different types of queries. The KeywordQuery class is appropriate for simple searches that are based on words, phrases, or prefixes. The FullTextSqlQuery class is for more complex queries that need to use advanced features of the search engine.

Using search does have implications for IT departments. The search services must be installed, set up, and maintained. However, many organizations rely on the search feature, and it is increasingly common for it to be part of the standard infrastructure. Although this guidance specifically discusses SharePoint search, any search engine that supports programmatic access is conceptually equivalent.

Using the FullTextSQLQuery Class

To perform queries that use the SQL syntax, use the Microsoft.Office.Server.Search.Query.FullTextSqlQuery class. The query text is very similar to the T-SQL queries that are used in SQL Server. Results from the queries are returned as Microsoft.Office.Server.Search.Query.ResultTableCollection objects. These objects can be loaded into an instance of System.Data.DataTable. For more information, see FullTextSqlQuery.

You can use scopes to narrow a search query. Scopes restrict the search to a subset of indexed items and can be defined in SharePoint's Central Administration. You can also use content types as a way to constrain search results.

The Partner Portal application uses an Incident Task content type for all incident tasks. The search is limited to content type and has an All Sites scope. The following query finds all incident tasks of type Incident Task across all sites.

SELECT Path, Title, AssignedTo, Status, Priority, ContentType FROM SCOPE() WHERE "SCOPE"='All Sites' AND ContentType = 'Incident Task' ORDER BY Path ASC

For more information about defining search scopes, see Define scopes for Searches on TechNet.

More Information

To learn more about the Search feature, see MOSS 2007 Search FAQ.

There are security issues to consider when you enable the Enterprise search feature. By default, sites that require forms-based authentication are not indexed. For more information, see SharePoint 2007 Tool: Add/Edit Crawl Rules with Form/Cookie Credentials.

To learn more about the search query object model, see Enterprise Search Query Object Model Overview on MSDN.

To learn more about the FullTextSqlQuery class, see SQL: FullTextSqlQuery Event Class on MSDN.

To learn more about the KeywordQuery class, see KeywordQuery Class (Microsoft.SharePoint.Search.Query) on MSDN.

To learn how to configure the Enterprise Search, see Walkthrough: Configuring Search for the AdventureWorks Business Data Application Sample on MSDN.

Home page on MSDN | Community site