@@ -72,7 +72,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
72
72
var fullStringToCompareWithoutCase = opt . IgnoreCase ? stringToCompare . ToLower ( ) : stringToCompare ;
73
73
var queryWithoutCase = opt . IgnoreCase ? query . ToLower ( ) : query ;
74
74
75
- var querySubstrings = queryWithoutCase . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
75
+ var querySubstrings = queryWithoutCase . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
76
76
int currentQuerySubstringIndex = 0 ;
77
77
var currentQuerySubstring = querySubstrings [ currentQuerySubstringIndex ] ;
78
78
var currentQuerySubstringCharacterIndex = 0 ;
@@ -92,7 +92,7 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
92
92
// If acronyms matching successfully finished, this gets the remaining not matched acronyms for score calculation
93
93
if ( currentAcronymQueryIndex >= query . Length && acronymsMatched == query . Length )
94
94
{
95
- if ( IsAcronym ( stringToCompare , compareStringIndex ) )
95
+ if ( IsAcronymCount ( stringToCompare , compareStringIndex ) )
96
96
acronymsTotalCount ++ ;
97
97
continue ;
98
98
}
@@ -117,9 +117,11 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
117
117
118
118
currentAcronymQueryIndex ++ ;
119
119
}
120
+ }
120
121
122
+ if ( IsAcronymCount ( stringToCompare , compareStringIndex ) )
121
123
acronymsTotalCount ++ ;
122
- }
124
+
123
125
// Acronym end
124
126
125
127
if ( allQuerySubstringsMatched || fullStringToCompareWithoutCase [ compareStringIndex ] !=
@@ -214,14 +216,46 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
214
216
}
215
217
216
218
private bool IsAcronym ( string stringToCompare , int compareStringIndex )
219
+ {
220
+ if ( IsAcronymChar ( stringToCompare , compareStringIndex ) || IsAcronymNumber ( stringToCompare , compareStringIndex ) )
221
+ return true ;
222
+
223
+ return false ;
224
+ }
225
+
226
+ // When counting acronyms, treat a set of numbers as one acronym ie. Visual 2019 as 2 acronyms instead of 5
227
+ private bool IsAcronymCount ( string stringToCompare , int compareStringIndex )
228
+ {
229
+ if ( IsAcronymChar ( stringToCompare , compareStringIndex ) )
230
+ return true ;
231
+
232
+ if ( char . IsNumber ( stringToCompare [ compareStringIndex ] ) || char . IsDigit ( stringToCompare [ compareStringIndex ] ) )
233
+ {
234
+ return compareStringIndex switch
235
+ {
236
+ int i when i == 0 => true ,
237
+ int i when char . IsWhiteSpace ( stringToCompare [ i - 1 ] ) => true ,
238
+ _ => false ,
239
+ } ;
240
+ }
241
+
242
+ return false ;
243
+ }
244
+
245
+ private bool IsAcronymChar ( string stringToCompare , int compareStringIndex )
217
246
{
218
247
if ( char . IsUpper ( stringToCompare [ compareStringIndex ] ) ||
219
- char . IsNumber ( stringToCompare [ compareStringIndex ] ) ||
220
- char . IsDigit ( stringToCompare [ compareStringIndex ] ) ||
221
- compareStringIndex == 0 ) //0 index means char is the start of the compare string, which is an acronym
248
+ compareStringIndex == 0 || //0 index means char is the start of the compare string, which is an acronym
249
+ compareStringIndex != 0 && char . IsWhiteSpace ( stringToCompare [ compareStringIndex - 1 ] ) )
222
250
return true ;
223
251
224
- if ( compareStringIndex != 0 && char . IsWhiteSpace ( stringToCompare [ compareStringIndex - 1 ] ) )
252
+ return false ;
253
+ }
254
+
255
+ private bool IsAcronymNumber ( string stringToCompare , int compareStringIndex )
256
+ {
257
+ if ( char . IsNumber ( stringToCompare [ compareStringIndex ] ) ||
258
+ char . IsDigit ( stringToCompare [ compareStringIndex ] ) )
225
259
return true ;
226
260
227
261
return false ;
0 commit comments