다음을 통해 공유


Enterprise Search Query Architecture

Applies to: SharePoint Server 2010

  • Federated Search Object Model
    With the Federated Search object model, you can bring results together from multiple search engines or repositories. You can use the federated search object model to query against SharePoint Server search, FAST Search Server 2010 for SharePoint, OpenSearch locations, and custom runtimes. The search result Web Parts in SharePoint Enterprise Search are built on top of the federated search object model.

  • Query Object Model
    In Enterprise Search in Microsoft Office SharePoint Server 2007, you used the query object model to create custom search Web Parts and search applications. SharePoint Server 2010 provides an updated version of this object model. You can use the query object model to query against SharePoint Server search and FAST Search Server 2010 for SharePoint. When you return results from SharePoint Server search and FAST Search Server 2010 for SharePoint using the federated search object model, the query object model is actually being called from the federated search object model.

Using the Federated Search Object Model

The federated search object model is implemented in the Microsoft.Office.Server.Search.Query namespace, found in the Microsoft.Office.Server.Search.dll. You must set references to the following DLLs to access the federated search object model:

  • Microsoft.Office.Server.dll

  • Microsoft.Office.Server.Search.dll

  • Microsoft.SharePoint.dll

Several classes provide the functionality in the object model. These classes are described in the following sections.

QueryManager

The QueryManager class is the entry point through which you access the other classes that are part of the federated search object model. This class submits the query request and returns the results. You can also modify the query from this class before it is submitted.

LocationList

The LocationList class contains a list of federated locations, and is responsible for aggregating the results from a location and returning them.

Location

The Location class represents a federated location in the object model.

ILocationRuntime

You use the ILocationRuntime interface if you need to provide an implementation for a custom provider.

Returning Search Results

The results are returned as XML. The following code example shows how to use the federated search object model to return search results:

    long lastupdate;
    bool crawl;
    SearchServiceApplicationProxy proxy =
(SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));
    LocationConfiguration[] locationConfigs;
    LocationConfiguration locationConfig = null;
    locationConfigs = proxy.GetLocationConfigurations(out lastupdate, out crawl);
    Location location;
    LocationList locationList = new LocationList();
    QueryManager queryManager = new QueryManager();
    foreach (LocationConfiguration locConfig in locationConfigs)
    {
        if (locConfig.InternalName.Equals("LocalSearchIndex"))
        {
            locationConfig = locConfig;
        break;
        }
    }
    location = new Location(locationConfig.InternalName, proxy);
    location.UserQuery = queryText;
    locationList.Add(location);
    queryManager.Add(locationList);
    queryManager.IsTriggered(locationList);
    XmlDocument xDoc = queryManager.GetResults(locationList);

For a complete, step-by-step walkthrough of this sample code, see Walkthrough: Creating a Basic Search Web Part Using the Federation Object Model.

Using the Query Object Model

The query search object model is implemented in the Microsoft.Office.Server.Search.Query namespace, found in the Microsoft.Office.Server.Search.dll. You must set references to the following DLLs to access the query object model:

  • Microsoft.Office.Server.dll

  • Microsoft.Office.Server.Search.dll

  • Microsoft.SharePoint.dll

About the Query Object Model Classes

The Microsoft.Office.Server.Search.Query namespace includes three query classes:

  • Query This class is not intended to be used directly from your code, but is designed to be the base implementation for the query object model classes. In your code, use the FullTextSqlQuery and KeywordQuery classes.

  • FullTextSqlQuery Use this class to execute SQL syntax search queries.

  • QueryKeywordQuery Use this class to execute Keyword syntax search queries.

SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));
KeywordQuery query = new KeywordQuery(proxy);
query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
query.QueryText = queryText;
query.ResultTypes |= ResultType.RelevantResults;
ResultTableCollection searchResults = query.Execute();
if (searchResults.Exists(ResultType.RelevantResults))
{
    ResultTable searchResult = searchResults[ResultType.RelevantResults];
    DataTable result = new DataTable();
    result.TableName = "Result";
    result.Load(searchResult, LoadOption.OverwriteChanges);
}

The following code example shows how to use the query object model to return search results

For a complete, step-by-step walkthrough of this sample code, see Walkthrough: Creating a Basic Search Web Part Using the Query Object Model.