Search code examples
c#azureazure-cognitive-searchazure-search-.net-sdk

Azure SuggestAsync map to POCO


i am using Azure search sdk 3.0.1 with syntax similar to below, where T is the POCO object , and i want List returned

   await indexClient.Documents.SuggestAsync<T>(input.Term, suggesterName,
                       indexType.GetAutoCompleteSearchParameters())

this gives me back DocumentSuggestResults, i did not see any examples or methods in azure sdk that will directly give me Ienumerable or convert this DocumentSuggestResults to Ienumerable . Is there a easy way to do this? or i need unpack this object myself loop and create a Ienumerable myself?


Solution

  • DocumentSuggestResults does not implement IEnumerable, but you can always just access the Results property and use LINQ to get at the documents:

    IEnumerable<SuggestResult<T>> results =
        (await indexClient.Documents.SuggestAsync<T>(input.Term, suggesterName,
                       indexType.GetAutoCompleteSearchParameters())).Results;
    IEnumerable<T> documents = results.Select(r => r.Document);