Skip to main content

Commands: SearchAsync

Syntax

#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);
Parameters
querystringThe query containing search criteria (you can use the built-in fields or metadata entries) consistent with Lucene syntax
sortFieldsstring[]The fields to sort by
startintThe start number to read index results
pageSizeintThe 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
.AsyncFilesCommands
.SearchAsync("AllowRead:Everyone", new []{ "__key"});

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
.AsyncFilesCommands
.SearchAsync(
"AllowRead:Everyone",
new[] { "__key", "-__fileName" } // sort ascending by full path, then by file name in descending order
);