5

I am working with SP2016 Farm solution.

I have configured a Search Service on my farm, customized the result source too. When I use the result source in Content Search WebPart on SharePoint Page, it gives me the result.

While I try to get the search result from the SSOM C# code, I get error

Your search cannot be completed because no Search service is available. Contact your administrator for more information.

I am using following set of code

SPSite currentSite = SPContext.Current.Site;
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("SEARCH SERVICE NAME");
SearchObjectOwner serviceApplicationOwner = new SearchObjectOwner(SearchObjectLevel.Ssa);
SourceRecord serviceApplicationResultSourceMedia = searchProxy.GetResultSourceByName("SEARCH RESULT SOURCE NAME", serviceApplicationOwner);

Till this the code works fine,

Now I am trying to use KeyWordQuery class to get the data from Search Result Source,

KeywordQuery query = new KeywordQuery("CURRENT SITE OBJECT");

I get the error

Your search cannot be completed because no Search service is available. Contact your administrator for more information.

Can anyone suggest me what I am missing?

5
  • Add the Microsoft.Office.Server.Search.Query reference to your solution

  • Then in your code behind, use this reference as the following

using Microsoft.SharePoint;
using Microsoft.Office.Server.Search.Query;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.