
Explanation/Reference:
Note:
Reference:
* Step 1:
First we need to add the necessary references such as.
usingMicrosoft.SharePoint.Client;
usingMicrosoft.SharePoint.Client.Search;
usingMicrosoft.SharePoint.Client.Search.Query;
Step 2:
Start by creating aClientContextobject and pass in the URL to a site. Put this in a using block.
Using(ClientContextclientContext =newClientContext("http://servername")) We then need to create aKeywordQueryclass to describe the query. This class is similar to the server sideKeywordQueryclass but there are some differences. We pass the ClientContext into the constructor.
KeywordQuerykeywordQuery =newKeywordQuery(clientContext);
* Step 3:
Unlike the server object model, with the Client OM we have to use another class,SearchExecutor, to send the queries to the search engine. We pass a ClientContext to it as well:
SearchExecutorsearchExecutor =newSearchExecutor(clientContext)
Step 4:
However, the query doesn't actually execute until you callExecuteQuery()on the ClientContext object. If you have done a lot of Client OM work before, you might think you need to callLoad()first but it is not required.
clientContext.ExecuteQuery();
Reference: How to: Query Search with the SharePoint 2013 Client Object Model