6

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?

3
  • 1
    Make sure you have used Microsoft.Office.Server.Search.Query namespace Commented Jan 16, 2018 at 12:02
  • 1
    Thanks @MohamedEl-QassasMVP, I too found the same reference. :-) Commented Jan 16, 2018 at 12:06
  • 1
    Glad to hear bro :) Commented Jan 16, 2018 at 12:09

1 Answer 1

6
  • 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 and acknowledge you have read our privacy policy.

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