/// <summary> /// Handle proj /// ect name scoring separately because of the 'with/without extension' /// </summary> /// <param name="projectInfo"></param> /// <param name="tokens"></param> /// <returns></returns> private decimal GetAssemblyNameScores(ProjectInfo projectInfo, IReadOnlyCollection <string> tokens) { const decimal scoreBaseValue = ScoreMultipliers.Name; if (projectInfo.AssemblyName == null) { return(0); } decimal score = 0; List <string> tokenizedSearchPhrase = SearchInputTokenizer.Tokenize(projectInfo.AssemblyName); foreach (string token in tokens) { if (projectInfo.AssemblyName.Equals(token, StringComparison.OrdinalIgnoreCase) || Path.GetFileNameWithoutExtension(projectInfo.AssemblyName).Equals(token, StringComparison.OrdinalIgnoreCase) ) { score += scoreBaseValue * ScoreMultipliers.Equal; } else if (this.TokenizedEquals(tokenizedSearchPhrase, token)) { score += scoreBaseValue * ScoreMultipliers.TokenizedEqual; } else if (projectInfo.AssemblyName.StartsWith(token, StringComparison.OrdinalIgnoreCase) || Path.GetFileNameWithoutExtension(projectInfo.AssemblyName).StartsWith(token, StringComparison.OrdinalIgnoreCase) ) { if (IsSufficientTokenLength(token)) { decimal bonus = GetPercentageBonus(scoreBaseValue * ScoreMultipliers.StartsWith, token, projectInfo.AssemblyName); score += (scoreBaseValue * ScoreMultipliers.StartsWith) + bonus; } } else if ((projectInfo.AssemblyName.Contains(token, StringComparison.OrdinalIgnoreCase) || Path.GetFileNameWithoutExtension(projectInfo.AssemblyName).Contains(token, StringComparison.OrdinalIgnoreCase)) && IsSufficientTokenLength(token) ) { decimal bonus = GetPercentageBonus(scoreBaseValue * ScoreMultipliers.Contains, token, projectInfo.AssemblyName); score += (scoreBaseValue * ScoreMultipliers.Contains) + bonus; } } return(score); }
private decimal GetStringScore(string toSearch, decimal scoreBaseValue, IEnumerable <string> tokens) { if (string.IsNullOrWhiteSpace(toSearch)) { return(0); } decimal score = 0; List <string> tokenizedSearchPhrase = SearchInputTokenizer.Tokenize(toSearch); foreach (string token in tokens) { if (toSearch.Equals(token, StringComparison.OrdinalIgnoreCase)) { score += scoreBaseValue * ScoreMultipliers.Equal; } else if (this.TokenizedEquals(tokenizedSearchPhrase, token)) { score += scoreBaseValue * ScoreMultipliers.TokenizedEqual; } else if (toSearch.StartsWith(token, StringComparison.OrdinalIgnoreCase)) { if (IsSufficientTokenLength(token)) { decimal bonus = GetPercentageBonus(scoreBaseValue * ScoreMultipliers.StartsWith, token, toSearch); score += (scoreBaseValue * ScoreMultipliers.StartsWith) + bonus; } } else if (toSearch.Contains(token, StringComparison.OrdinalIgnoreCase) && IsSufficientTokenLength(token)) { decimal bonus = GetPercentageBonus(scoreBaseValue * ScoreMultipliers.Contains, token, toSearch); score += (scoreBaseValue * ScoreMultipliers.Contains) + bonus; } } return(score); }