Josh
Josh

Reputation: 3611

Error accessing Search API using C# in SharePoint 2013: Your search cannot be completed because no Search service is available

I am using the server-side object model to try and call the search service (for querying against the search index). The code looks like this:

using (SPSite siteCollection = new SPSite(http://ValidSharePointSite))
                {
                    KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
                    keywordQuery.QueryText = "search text";
                    SearchExecutor searchExecutor = new SearchExecutor();
                    ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
                    resultTableCollection.Filter("Pages", KnownTableTypes.RelevantResults);
                    ResultTable resultTable = resultTableCollection.FirstOrDefault();
                    DataTable dataTable = resultTable.Table;
            }

When it hits the line where the KeywordQuery object is created, the following error is thrown: Your search cannot be completed because no Search service is available

I've tried the code on two different SharePoint servers/envs and the same issue happens. There is some additional info in the logs about not being able to find the HostController Service. Any suggestions?

Upvotes: 1

Views: 1773

Answers (2)

Josh
Josh

Reputation: 3611

Here's the solution: http://coder87.wordpress.com/2013/03/27/keywordquery-doesnt-work-or-confusion-between-search-namespaces/#comment-484

Must use Microsoft.Office.Server.Search.Query instead of Microsoft.SharePoint.Search.Query;

Upvotes: 3

user3659673
user3659673

Reputation: 1

Make sure that your search service is up and no errors specified. Also through Search REST API in browser you can able to validate if search is working correctly

Upvotes: 0

Related Questions