@@ -54,9 +54,55 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
54
54
stringToCompare = _alphabet . Translate ( stringToCompare ) ;
55
55
}
56
56
57
+ // This also can be done by spliting the query
58
+
59
+ //(var spaceSplit, var upperSplit) = stringToCompare switch
60
+ //{
61
+ // string s when s.Contains(' ') => (s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(w => w.First()),
62
+ // default(IEnumerable<char>)),
63
+ // string s when s.Any(c => char.IsUpper(c)) && s.Any(c => char.IsLower(c)) =>
64
+ // (null, Regex.Split(s, @"(?<!^)(?=[A-Z])").Select(w => w.First())),
65
+ // _ => ((IEnumerable<char>)null, (IEnumerable<char>)null)
66
+ //};
67
+
68
+ var currentQueryIndex = 0 ;
69
+ var acronymMatchData = new List < int > ( ) ;
70
+ var queryWithoutCase = opt . IgnoreCase ? query . ToLower ( ) : query ;
71
+
72
+ int acronymScore = 100 ;
73
+
74
+ for ( int compareIndex = 0 ; compareIndex < stringToCompare . Length ; compareIndex ++ )
75
+ {
76
+ if ( currentQueryIndex >= queryWithoutCase . Length )
77
+ break ;
78
+
79
+ if ( compareIndex == 0 && queryWithoutCase [ currentQueryIndex ] == char . ToLower ( stringToCompare [ compareIndex ] ) )
80
+ {
81
+ acronymMatchData . Add ( compareIndex ) ;
82
+ currentQueryIndex ++ ;
83
+ continue ;
84
+ }
85
+
86
+ switch ( stringToCompare [ compareIndex ] )
87
+ {
88
+ case char c when ( char . IsUpper ( c ) && char . ToLower ( c ) == queryWithoutCase [ currentQueryIndex ] )
89
+ || ( char . IsWhiteSpace ( c ) && char . ToLower ( stringToCompare [ ++ compareIndex ] ) == queryWithoutCase [ currentQueryIndex ] ) :
90
+ acronymMatchData . Add ( compareIndex ) ;
91
+ currentQueryIndex ++ ;
92
+ continue ;
93
+
94
+ case char c when char . IsWhiteSpace ( c ) :
95
+ compareIndex ++ ;
96
+ acronymScore -= 10 ;
97
+ break ;
98
+ case char c when char . IsUpper ( c ) :
99
+ acronymScore -= 10 ;
100
+ break ;
101
+ }
102
+ }
103
+
57
104
var fullStringToCompareWithoutCase = opt . IgnoreCase ? stringToCompare . ToLower ( ) : stringToCompare ;
58
105
59
- var queryWithoutCase = opt . IgnoreCase ? query . ToLower ( ) : query ;
60
106
61
107
var querySubstrings = queryWithoutCase . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
62
108
int currentQuerySubstringIndex = 0 ;
0 commit comments