Getting Started with the SharePoint Server Search Administration Object Model
Applies to: SharePoint Server 2010
Accessing the SharePoint Server Search Administration Object Model
To use the SharePoint Server search Administration object model, you must set references to the following DLLs in your project:
Microsoft.SharePoint.dll
Microsoft.Office.Server.dll
Microsoft.Office.Server.Search.dll
You must include the following namespace directives at the beginning of the class file.
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server.Search.Administration;
SearchServiceApplication Class
The SearchServiceApplication class represents an instance of a Search service application in a farm. You can access the administration settings for a Search service application by using the following code
SearchService searchService = SearchService.Service;
SearchServiceApplication searchApp = searchService.SearchApplications.GetValue<SearchServiceApplication>(new Guid("SearchApplicationID"));
SearchServiceApplicationProxy Class
The SearchServiceApplicationProxy class represents a connection to a Search service application in a farm. The following code retrieves the instance of the SearchServiceApplicationProxy class for the current site.
SPServiceContext serviceContext = SPServiceContext.Current;
SPServiceApplicationProxy proxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy));
SearchServiceApplicationProxy searchAppProxy = proxy as SearchServiceApplicationProxy;
Warning
The previous code works only when the Current property does not return null.
You can then use the SearchServiceApplicationProxy instance to access the Search service application.