{"id":310,"date":"2011-06-01T16:08:24","date_gmt":"2011-06-01T16:08:24","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=310"},"modified":"2011-06-01T16:08:24","modified_gmt":"2011-06-01T16:08:24","slug":"get-searchserviceapplication","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2011\/06\/01\/get-searchserviceapplication\/","title":{"rendered":"Get SearchServiceApplication object instance"},"content":{"rendered":"<p>Looking to retrieve the SearchServiceApplication object for the current site?  It&#8217;s pretty straight forward, as the following demonstrates:<\/p>\n<p>Start by adding the following namespace to your class<\/p>\n<pre lang=\"xml\">\r\nusing Microsoft.Office.Server.Search.Administration;\r\n<\/pre>\n<p>The Microsoft.Office.Server assembly can be found in the ISAPI folder of the SharePoint hive.<br \/>\n<!--more--><br \/>\nTo get the instance of the SearchServiceApplication for the current site we first need to get the SPServiceContext for the current site.  Next, using this context object, we retrieve the proxy class for the SearchServiceApplication, which is called SearchServiceApplicationProxy.<\/p>\n<p>Using the proxy class the next step is to retrieve the application identifier for the search service application service, which we will then use to retrieve the SearchServiceApplication instance for the site.<\/p>\n<p>After this we will have the current site&#8217;s SearchServiceApplication class instance object.<\/p>\n<pre lang=\"csharp\">\r\n\/\/ Get the service context for the current site\r\nSPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);\r\n\/\/ Get the SearchApplicationProxy object from service context object\r\nSearchServiceApplicationProxy searchApplicationProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;\r\n\/\/ Get the identifier for the search service application from the proxy class retrieved above.\r\nGuid applicationId = searchApplicationProxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;\r\n\/\/ Lastly, retreieve the SearchServiceApplication object for the current site.\r\nSearchServiceApplication searchApplication = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(applicationId);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Looking to retrieve the SearchServiceApplication object for the current site? It&#8217;s pretty straight forward, as the following demonstrates: Start by adding the following namespace to your class using Microsoft.Office.Server.Search.Administration; The Microsoft.Office.Server assembly can be found in the ISAPI folder of &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2011\/06\/01\/get-searchserviceapplication\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[3],"tags":[20,81],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-50","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/310"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":6,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":316,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/310\/revisions\/316"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}