public async Task <List <Listing> > SearchListings(int resumeId, string phrase, string location, bool isFullTime) { //load resumes var resumeEntity = uow.ResumeRepository.GetById(resumeId); if (resumeEntity == null) { throw new ArgumentNullException("Resume was null"); } var listings = await listingService.SearchListings(phrase, location, isFullTime); var resume = new ResumeFile(resumeEntity); return(ranker.Rank(resume, listings)); }
// Call Rank() on the given IRanker then transform its result into a message which is // informative to the end user. public static (string strong, string normal) RankAndHumanify(IRanker ranker, string query) { string rankings; try { rankings = ranker.Rank(query, TARGET_SITE); } catch (ExtractionException ex) { return("Error: ", ex.Message); } if (rankings == "0") { return("Result: ", $"The site '{TARGET_SITE}' could not be found in the search results."); } string inflected_index = rankings.Split(' ').Length == 1 ? "index" : "indices"; return("Result: ", $"The site '{TARGET_SITE}' was found at the following {inflected_index} (where 1 represents the first search result): {rankings}."); }
public IEnumerable <SearchResult> Search(string query) { if (query == null || query.Trim() == "") { yield break; } query = query.Trim(); var session = SessionId++; mLogger.Log(nameof(SearchEngine), session + "\tSearching: " + query); var time = DateTime.Now; var parsedQuery = mQueryParser.Parse(query); mLogger.Log(nameof(SearchEngine), session + "\tParsed query " + (DateTime.Now - time).TotalMilliseconds); time = DateTime.Now; var urlFileIds = mRetriever.Retrieve(parsedQuery.Expression).ToList(); var count = urlFileIds.Count; mLogger.Log(nameof(SearchEngine), session + "\tRetrieved docs " + (DateTime.Now - time).TotalMilliseconds); time = DateTime.Now; var scores = mRanker.Rank(urlFileIds, parsedQuery.Words).ToList(); mLogger.Log(nameof(SearchEngine), session + "\tRanked docs 1 " + (DateTime.Now - time).TotalMilliseconds); time = DateTime.Now; var results = new List <SearchResult>(); for (int i = 0; i < count; ++i) { results.Add(new SearchResult { UrlFileId = urlFileIds[i], Score = scores[i], }); } results = results.OrderByDescending(o => o.Score.Value).ToList(); for (int i = 0; i < (PageSize - 1 + count) / PageSize; ++i) { int subResultsLength = Math.Min(PageSize, count - PageSize * i); var subResults = results.GetRange(i * PageSize, subResultsLength); var proScores = mProRanker.Rank(subResults.Select(o => o.UrlFileId), parsedQuery.Words).ToList(); for (int j = 0; j < subResultsLength; ++j) { subResults[j].ProScore = proScores[j]; subResults[j].WordPositions = proScores[j].WordPositions?.Where(o => o.Position != uint.MaxValue); } mLogger.Log(nameof(SearchEngine), session + "\tRanked docs 2 " + (DateTime.Now - time).TotalMilliseconds); time = DateTime.Now; foreach (var proResult in subResults.OrderByDescending(o => o.ProScore.Value)) { yield return(proResult); } } }