public async Task <ODataResult <TEntity> > RetrieveItemsAsync <TEntity>(IODataQueryable <TEntity> query, CancellationToken cancellation) { var info = GetEntityInfo <TEntity>(); var parameters = new SearchOptions { Filter = query.Filter, Size = query.Take, Skip = query.Skip, IncludeTotalCount = true, }; AddRange(parameters.OrderBy, query.Order); AddRange(parameters.Select, query.Select); string search = null; if (query is AzureQueryable <TEntity> azq) { AddRange(parameters.SearchFields, azq.SearchFields); parameters.SearchMode = azq.SearchMode; parameters.QueryType = azq.QueryType; search = azq.Search; } var response = await info.Index.SearchAsync <TEntity>(search, parameters, cancellation); return(await ODataAzureSearchResult <TEntity> .MakeResultAsync(response, cancellation)); }
public static async Task <ODataAzureSearchResult <TEntity> > MakeResultAsync(Response <SearchResults <TEntity> > response, CancellationToken cancellation) { var result = new ODataAzureSearchResult <TEntity>(); var results = response.Value.GetResultsAsync(); if (typeof(IResourceWithScore).IsAssignableFrom(typeof(TEntity))) { result.Items = await results.Select(a => { var res = a.Document; ((IResourceWithScore)res).Score = a.Score; return(res); }).ToListAsync(cancellation); } else { result.Items = await results.Select(a => a.Document).ToListAsync(cancellation); } result.Total = response.Value.TotalCount; return(result); }