Skip to content

Commit 8a76ad0

Browse files
committed
Add number support (treat number as part of acronuym)
1 parent 787e569 commit 8a76ad0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public MatchResult FuzzyMatch(string query, string stringToCompare)
4444
/// </summary>
4545
public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption opt)
4646
{
47-
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult (false, UserSettingSearchPrecision);
48-
47+
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult(false, UserSettingSearchPrecision);
48+
4949
query = query.Trim();
5050

5151
stringToCompare = _alphabet?.Translate(stringToCompare) ?? stringToCompare;
@@ -83,7 +83,8 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
8383
{
8484
case char c when compareIndex == 0 && queryWithoutCase[currentQueryIndex] == char.ToLower(stringToCompare[compareIndex])
8585
|| (char.IsUpper(c) && char.ToLower(c) == queryWithoutCase[currentQueryIndex])
86-
|| (char.IsWhiteSpace(c) && char.ToLower(stringToCompare[++compareIndex]) == queryWithoutCase[currentQueryIndex]):
86+
|| (char.IsWhiteSpace(c) && char.ToLower(stringToCompare[++compareIndex]) == queryWithoutCase[currentQueryIndex])
87+
|| (char.IsNumber(c) && c == queryWithoutCase[currentQueryIndex]):
8788
acronymMatchData.Add(compareIndex);
8889
currentQueryIndex++;
8990
continue;
@@ -92,7 +93,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
9293
compareIndex++;
9394
acronymScore -= 10;
9495
break;
95-
case char c when char.IsUpper(c):
96+
case char c when char.IsUpper(c) || char.IsNumber(c):
9697
acronymScore -= 10;
9798
break;
9899
}
@@ -103,7 +104,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
103104

104105
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
105106

106-
107+
107108
var querySubstrings = queryWithoutCase.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
108109
int currentQuerySubstringIndex = 0;
109110
var currentQuerySubstring = querySubstrings[currentQuerySubstringIndex];
@@ -186,7 +187,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
186187
currentQuerySubstringCharacterIndex = 0;
187188
}
188189
}
189-
190+
190191
// proceed to calculate score if every char or substring without whitespaces matched
191192
if (allQuerySubstringsMatched)
192193
{
@@ -229,7 +230,7 @@ private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQ
229230

230231
return allMatch;
231232
}
232-
233+
233234
private static List<int> GetUpdatedIndexList(int startIndexToVerify, int currentQuerySubstringCharacterIndex, int firstMatchIndexInWord, List<int> indexList)
234235
{
235236
var updatedList = new List<int>();

0 commit comments

Comments
 (0)