I have a web app API which using ACS V11 SDK to search index documents and return the search results. Bellow is simplified code in my API interface:
public async Task<SearchResults<SearchDocument>> SearchIndexDocumentsAsync(
[FromBody] SearchParameters parameters,
CancellationToken cancellationToken = default)
{
var searchIndexClient = new SearchIndexClient(
new Uri(endpoint),
new AzureKeyCredential(apiKey));
var searchClient = searchIndexClient.GetSearchClient(indexName);
SearchResults<SearchDocument> docs = await searchClient.SearchAsync<SearchDocument>(parameters.Query, searchOptions: null, cancellationToken).ConfigureAwait(false);
return docs;
}
The problem is, the response Json only contains total count, but no document results, like below:
{
"totalCount": 19
}
I know I can iterate all documents from ACS SDK response and add them to a list like this:
var results = new List<SearchResult<SearchDocument>>();
await foreach (SearchResult<SearchDocument> document in docs.GetResultsAsync())
{
results.Add(document);
}
return results;
But is there any easier way to return the full search results including documents without having to iterate all document?