Beispiel #1
0
        public static int IndexOfBestMatch(string needle, string[] haystack)
        {
            var index  = 0;
            var scored = new Dictionary <int, double>();
            var input  = Path.GetFileNameWithoutExtension(needle);

            foreach (var item in haystack)
            {
                if (item.Equals(input, StringComparison.OrdinalIgnoreCase))
                {
                    return(index); // direct match
                }
                scored[index++] = FilenameDiff.GetDiffScore(input, item);
            }

            // score: the lower, the better.
            if (scored.Count > 0)
            {
                return(scored.OrderBy(x => x.Value).First().Key);
            }

            return(-1);
        }
Beispiel #2
0
 private static Subtitle FindBestSearchResultMatch(string name, Subtitle[] searchResults)
 {
     return(FilenameDiff.FindBestMatch <Subtitle>(name, searchResults, x => x.MovieReleaseName));
 }
Beispiel #3
0
 private Subtitle FindBestSearchResultMatch(string name, Subtitle[] searchResults)
 {
     logger.Debug($"@gray@Finding best match for '{name}'...");
     return(FilenameDiff.FindBestMatch <Subtitle>(name, searchResults, x => x.MovieReleaseName));
 }