0

I have a sharepoint installation with multiple site collections, let's say siteA, siteB e.t.c

I am using the following code to search in sharepoint

    using (ClientContext context = Connect())
    {
         KeywordQuery keywordQuery = new KeywordQuery(context);
         keywordQuery.QueryText = "text to search";
         SearchExecutor searchExecutor = new SearchExecutor(context);
         ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
         context.ExecuteQuery();
     }   

and the results i am getting are from all sites siteA, siteB etc. Is there anyway to specify that i want the search to be performed only in siteA and to be even more specific only in Shared Documents of siteA?

0

Search scopes have been replaced by Result Sources in SP2013.

To specify a result source you'll want to set the source ID on the Keyword Query to the GUID of the result source. E.g.:

var context = SP.ClientContext.get_current();

 var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context);

 keywordQuery.set_queryText("Search Query");

 // Set Source ID (GUID)

 keywordQuery.set_sourceId("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");


 var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(context);

var results = searchExecutor.executeQuery(keywordQuery);

context.executeQueryAsync(onQuerySuccess, onQueryFail);

Additional Search CSOM examples can be found here.

  • Yes i know the concept of search scopes. How do i find the GUID of a search scope once i create it? – gefrag May 11 '15 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.