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:
Step 1
First we need to add the necessary references such as. using MicrosoftSharePoint.Client; using MicrosoftSharePoint.ClientSearch; using MicrosoftSharePoint.ClientSearch.Query;
Step 2
Start by creating a ClientContext object and pass in the URL to a site. Put this in a using block. using (CiientContext 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 KeywordQuery class but there are some differences. We pass the ClientContext into the constructor. var keywordQuery = new KeywordQuery(context);
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 var searchExecutor = new SearchExecutor(context);
Step4
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 var results = searchExecutor.executeQuery(keywordQuery);
Not Retrieve: ClientObject.Retrieve method retrieves all scalar properties associated with the object. This member is reserved for internal use and is not intended to be used directly from your code.
http://code.msdn.microsoft.com/office/SharePoint-2013-Querying-a629b53b
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.search.query.searchexecutor.aspx