You develop a SharePoint app that uses the client-side object model (CSOM) to retrieve items from the search index.
You need to implement the client-side query code.
Which four code segments should you use in sequence? (To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the correct order.)
Select and Place:
Correct Answer:
Explanation/Reference:
Note: Reference:
* Step 1:
First we need to add the necessary references such as. using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Search;
using Microsoft.SharePoint.Client.Search.Query;
* Step 2:
Start by creating a ClientContext object and pass in the URL to a site. Put this in a using block. using (ClientContext clientContext = new ClientContext("http://servername"))
We then need to create a KeywordQuery class to describe the query. This class is similar to the server side Key wordQuery class but there are some differences. We pass the ClientContext into the constructor.
KeywordQuery keywordQuery = new KeywordQuery(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:
SearchExecutor searchExecutor = new SearchExecutor(clientContext) Step 4:
However, the query doesn’t actually execute until you call ExecuteQuery() on the ClientContext object. If you have done a lot of Client OM work before, you might think you need to call Load() first but it is not required.
clientContext.ExecuteQuery();
Reference: How to: Query Search with the SharePoint 2013 Client Object Model