src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/FuzzyMatching.cs
/// <summary>
/// Finds the best match (the one with the most
/// number of letters adjacent to each other) and
/// returns the index location of each of the letters
/// of the matches
/// </summary>
/// <param name="text">The text to search inside of</param>
/// <param name="searchText">the text to search for</param>
/// <returns>returns the index location of each of the letters of the matches</returns>
Finds the best match (the one with the most
number of letters adjacent to each other) and
returns the index location of each of the letters
of the matches
Finds the best match ( the one with the most number of letters adjacent to each other ) and returns the index location of each of the letters of the matches
public static List<int> FindBestFuzzyMatch(string text, string searchText)
        {
            searchText = searchText.ToLower();
            text = text.ToLower();
            bool[,] matches = new bool[text.Length, searchText.Length];
            for (int firstIndex = 0; firstIndex < text.Length; firstIndex++)
            {
                for (int secondIndex = 0; secondIndex < searchText.Length; secondIndex++)
                {
                    matches[firstIndex, secondIndex] =
                        searchText[secondIndex] == text[firstIndex] ?
                        true :
                        false;
                }
            }
            List<List<int>> allMatches = GetAllMatchIndexes(matches);
            int maxScore = allMatches.Count > 0 ? CalculateScoreForMatches(allMatches[0]) : 0;
            List<int> bestMatch = allMatches.Count > 0 ? allMatches[0] : new List<int>();
            foreach (var match in allMatches)
            {
                int score = CalculateScoreForMatches(match);
                if (score > maxScore)
                {
                    bestMatch = match;
                    maxScore = score;
                }
            }
            return bestMatch;
        }
public static List < int > FindBestFuzzyMatch ( string text , string searchText ) { searchText = searchText . ToLower ( ) ; text = text . ToLower ( ) ; bool [ , ] matches = new bool [ text . Length , searchText . Length ] ; for ( int firstIndex = 0 ; firstIndex < text . Length ; firstIndex ++ ) { for ( int secondIndex = 0 ; secondIndex < searchText . Length ; secondIndex ++ ) { matches [ firstIndex , secondIndex ] = searchText [ secondIndex ] == text [ firstIndex ] ? true : false ; } } List < List < int > > allMatches = GetAllMatchIndexes ( matches ) ; int maxScore = allMatches . Count > 0 ? CalculateScoreForMatches ( allMatches [ 0 ] ) : 0 ; List < int > bestMatch = allMatches . Count > 0 ? allMatches [ 0 ] : new List < int > ( ) ; foreach ( var match in allMatches ) { int score = CalculateScoreForMatches ( match ) ; if ( score > maxScore ) { bestMatch = match ; maxScore = score ; } } return bestMatch ; }
Finds the best match (the one with the most
number of letters adjacent to each other) and
returns the index location of each of the letters
of the matches
Finds the best match ( the one with the most number of letters adjacent to each other ) and returns the index location of each of the letters of the matches
// Create a grid to march matches like // eg. //   a b c a d e c f g // a x     x // c     x       x // use this table to get all the possible matches // return the score that is the max
returns the index location of each of the letters of the matches
returns the index location of each of the letters of the matches
text
string
The text to search inside of
The text to search inside of
searchText
string
the text to search for
the text to search for