private async Task <IList <T> > FetchResults() { IList <T> results = await searchResultProvider.FetchAll(); foreach (T result in results) { if (result.GetMetadata <ResultMetadata>(Algorithm) == null) { ResultMetadata resultMetadata = ParseResult(result); result.AddMetadata(Algorithm, resultMetadata); } } return(results); }
public async Task <IList <T> > Search(string searchTerm, int maxResults, bool asYouType) { await EnsureInitialized(); IList <SearchWord> searchPhrase = ParseSearchPhrase(searchTerm, asYouType); var ranks = new Dictionary <T, Rank>(); foreach (T result in await FetchResults()) { ResultMetadata resultMetadata = result.GetMetadata <ResultMetadata>(Algorithm); Rank rank = Match(searchPhrase, resultMetadata.ResultTerms); ranks.Add(result, rank); } return(ranks .Where(r => r.Value.Confidence >= ConfidenceThreshold) .OrderByDescending(r => r.Value.Relevance) .Take(maxResults) .Select(r => r.Key) .ToList()); }