4

I'm creating a new ClientContext:

ClientContext clientContext = new ClientContext(targetUrl); 

When trying to do a simple search:

KeywordQuery keywordQuery = new KeywordQuery(clientContext); keywordQuery.QueryText = "test"; SearchExecutor searchExecutor = new SearchExecutor(clientContext); var results = searchExecutor.ExecuteQuery(keywordQuery); context.ExecuteQuery(); 

The results are returned, but only for the site from the targetUrl used in the context. Is there any way to return results across all sites using .Net CSOM Search?

2 Answers 2

1

I needed to add <AppPermissionRequest Scope=”http://sharepoint/search” Right=”QueryAsUserIgnoreAppPrincipal” /> to appmanifest.xml to query against the farm. Without setting this permissions, search will only return results from the site the app is installed on.

0

You could tweak the query text by introducing ContentClass managed property, to retrieve results across all the sites:

keywordQuery.QueryText = "contentclass=\"STS_Web\" AND contentclass=\"STS_Site\""; 
2
  • 2
    Thank you for the answer, but, I might have misspoke. I'm not trying to get all sites, I'm trying to search across all sites Commented Jun 27, 2014 at 12:18
  • Sorry, I meant to search across all sites but I missed out on some words. See my updated response. The query will you results across all sites. Commented Jun 27, 2014 at 20:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.