To work with SharePoint 2013 server object model SharePoint should be installed on the server.
Here we will see how we can do search using KeywordQuery class in SharePoint 2013.
First give reference to the below dll which are located in 15 hive folder under ISAPI folder.
using (SPSite siteCollection = new SPSite("http://SiteURL"))
KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
keywordQuery.QueryText = "SharePoint 2013";
SearchExecutor searchExecutor = new SearchExecutor();
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
resultTableCollection = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
ResultTable resultTable = resultTableCollection.FirstOrDefault();
DataTable dataTable = resultTable.Table;
Here in SharePoint 2013, a new class name as SearchExecutor has been provided. To submit the query we should use the ExecuteQuery() method of the SearchExecutor class.
Remember in SharePoint 2010 search
, we were using Execute method which is obsolete now. Though it will work, but we should use SearchExecutor class.