Skip to content

Commit

Permalink
Check the null for searchResult.Value before call GetResultsAsync() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Mar 28, 2024
1 parent 6e227d0 commit 7e9f3ac
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public async Task<IEnumerable<SearchDocument>> SearchAsync(string indexName, str
var searchResult = await client.SearchAsync<SearchDocument>(searchText, searchOptions);
var counter = 0L;

if (searchResult.Value is null)
{
return counter;
}

await foreach (var doc in searchResult.Value.GetResultsAsync())
{
action(doc.Document);
counter++;
}

return searchResult.Value?.TotalCount ?? counter;
return searchResult.Value.TotalCount ?? counter;
}

public async Task DeleteDocumentsAsync(string indexName, IEnumerable<string> contentItemIds)
Expand Down

0 comments on commit 7e9f3ac

Please sign in to comment.