You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Commands: SearchAsync

Use the SearchAsync method to fetch the list of files matching the specified query.


Task<SearchResults> SearchAsync(string query, string[] sortFields = null, int start = 0, int pageSize = 1024);
query string The query containing search criteria (you can use the built-in fields or metadata entries) consistent with Lucene syntax
sortFields string[] The fields to sort by
start int The start number to read index results
pageSize int The max number of results that will be returned

Return Value
Task<SearchResults> A task that represents the asynchronous operation. The task result is SearchResults object which represents results of a specified query.

Example I

In order to get the list of files that has Everyone value under the AllowRead metadata key returned in ascending order by a full file name (stored under built-in __key field), you need to build the following query:

SearchResults results = await store
	.SearchAsync("AllowRead:Everyone", new []{ "__key"});

Results order

There is a convention which determines the ordering type: ascending or descending. The usage of + symbol or no prefix before a name of the sorted field means that ascending sorting will be applied. In order to retrieve results in descending order you need to add - sign before the field name.

Example II

SearchResults results = await store
		new[] { "__key", "-__fileName" } // sort ascending by full path, then by file name in descending order