You develop a SharePoint app that uses the client-side object model (CSOM) to run search queries.
You need to implement a method that searches for the term SharePoint.
Which code segments should you include to complete the code?
(To answer, drag the appropriate code segment to the correct targets in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:
Correct Answer:
Explanation/Reference:
(Target 1, Target 2): KeywordQuery
We need to create a KeywordQuery class to describe the query.
We pass the ClientContext into the constructor.
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
To set the query use the QueryText property. Here we are doing a search for the keyword "SharePoint". keywordQuery.QueryText = "SharePoint";
(Target 3, Target 4): SearchExecutor.ExecuteQuery method runs a query.
ClientResult
(Target 5): To execute the query, we use the ExecuteQuery method. It returns a type of
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
Reference: How to: Query Search with the SharePoint 2013 Client Object Model