How to resolve “Your search cannot be completed because no Search service is available. Contact your administrator for more information.”?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/233866

Question

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?

Was it helpful?

Solution

  • 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;

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top