Add number support (treat number as part of acronuym)

This commit is contained in:
弘韬 张 2020-10-24 17:45:31 +08:00 committed by 张弘韬
parent 787e569604
commit 8a76ad000d

View file

@ -44,8 +44,8 @@ namespace Flow.Launcher.Infrastructure
/// </summary>
public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption opt)
{
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult (false, UserSettingSearchPrecision);
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult(false, UserSettingSearchPrecision);
query = query.Trim();
stringToCompare = _alphabet?.Translate(stringToCompare) ?? stringToCompare;
@ -83,7 +83,8 @@ namespace Flow.Launcher.Infrastructure
{
case char c when compareIndex == 0 && queryWithoutCase[currentQueryIndex] == char.ToLower(stringToCompare[compareIndex])
|| (char.IsUpper(c) && char.ToLower(c) == queryWithoutCase[currentQueryIndex])
|| (char.IsWhiteSpace(c) && char.ToLower(stringToCompare[++compareIndex]) == queryWithoutCase[currentQueryIndex]):
|| (char.IsWhiteSpace(c) && char.ToLower(stringToCompare[++compareIndex]) == queryWithoutCase[currentQueryIndex])
|| (char.IsNumber(c) && c == queryWithoutCase[currentQueryIndex]):
acronymMatchData.Add(compareIndex);
currentQueryIndex++;
continue;
@ -92,7 +93,7 @@ namespace Flow.Launcher.Infrastructure
compareIndex++;
acronymScore -= 10;
break;
case char c when char.IsUpper(c):
case char c when char.IsUpper(c) || char.IsNumber(c):
acronymScore -= 10;
break;
}
@ -103,7 +104,7 @@ namespace Flow.Launcher.Infrastructure
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
var querySubstrings = queryWithoutCase.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int currentQuerySubstringIndex = 0;
var currentQuerySubstring = querySubstrings[currentQuerySubstringIndex];
@ -186,7 +187,7 @@ namespace Flow.Launcher.Infrastructure
currentQuerySubstringCharacterIndex = 0;
}
}
// proceed to calculate score if every char or substring without whitespaces matched
if (allQuerySubstringsMatched)
{
@ -229,7 +230,7 @@ namespace Flow.Launcher.Infrastructure
return allMatch;
}
private static List<int> GetUpdatedIndexList(int startIndexToVerify, int currentQuerySubstringCharacterIndex, int firstMatchIndexInWord, List<int> indexList)
{
var updatedList = new List<int>();