public static async Task <SearchComicResult> SearchAsync(this SearchEngine eng, string keyword, int skip, int take) { using (var scope = eng.ServiceScopeFactory.CreateScope()) { var result = new SearchComicResult { Total = 0 }; var datas = new List <ComicSnapshot>(); foreach (var item in eng) { var prov = (ISearchProvider)scope.ServiceProvider.GetRequiredService(item); var dt = await prov.SearchAsync(keyword, skip, take); if (dt != null && dt.Support && dt.Snapshots != null) { result.Support = dt.Support; datas.AddRange(dt.Snapshots); result.Total += dt.Total; } } result.Snapshots = datas.ToArray(); return(result); } }
public static Task <IComicCursor> GetSearchCursorAsync(this SearchEngine eng, string keyword, int skip = 0, int take = 50) { var scope = eng.ServiceScopeFactory.CreateScope(); return(Task.FromResult <IComicCursor>(new DefaultComicCursor(scope, eng.GetEnumerator(), keyword, skip, take))); }