Skip to content

Commit 706f30a

Browse files
committed
Add number support (treat number as part of acronuym)
1 parent 4d06187 commit 706f30a

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;
@@ -77,7 +77,8 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
7777
{
7878
case char c when (compareIndex == 0 && queryWithoutCase[currentQueryIndex] == char.ToLower(stringToCompare[compareIndex]))
7979
|| (char.IsUpper(c) && char.ToLower(c) == queryWithoutCase[currentQueryIndex])
80-
|| (char.IsWhiteSpace(c) && char.ToLower(stringToCompare[++compareIndex]) == queryWithoutCase[currentQueryIndex]):
80+
|| (char.IsWhiteSpace(c) && char.ToLower(stringToCompare[++compareIndex]) == queryWithoutCase[currentQueryIndex])
81+
|| (char.IsNumber(c) && c == queryWithoutCase[currentQueryIndex]):
8182
acronymMatchData.Add(compareIndex);
8283
currentQueryIndex++;
8384
continue;
@@ -86,7 +87,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
8687
compareIndex++;
8788
acronymScore -= 10;
8889
break;
89-
case char c when char.IsUpper(c):
90+
case char c when char.IsUpper(c) || char.IsNumber(c):
9091
acronymScore -= 10;
9192
break;
9293
}
@@ -97,7 +98,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
9798

9899
var fullStringToCompareWithoutCase = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
99100

100-
101+
101102
var querySubstrings = queryWithoutCase.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
102103
int currentQuerySubstringIndex = 0;
103104
var currentQuerySubstring = querySubstrings[currentQuerySubstringIndex];
@@ -180,7 +181,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
180181
currentQuerySubstringCharacterIndex = 0;
181182
}
182183
}
183-
184+
184185
// proceed to calculate score if every char or substring without whitespaces matched
185186
if (allQuerySubstringsMatched)
186187
{
@@ -223,7 +224,7 @@ private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQ
223224

224225
return allMatch;
225226
}
226-
227+
227228
private static List<int> GetUpdatedIndexList(int startIndexToVerify, int currentQuerySubstringCharacterIndex, int firstMatchIndexInWord, List<int> indexList)
228229
{
229230
var updatedList = new List<int>();

0 commit comments

Comments
 (0)