diff --git a/src/kiss/FuzzyMap.hx b/src/kiss/FuzzyMap.hx index b70df26..5119d30 100644 --- a/src/kiss/FuzzyMap.hx +++ b/src/kiss/FuzzyMap.hx @@ -21,6 +21,10 @@ abstract FuzzyMap(StringMap) from StringMap to StringMap { } static var threshold = 0.4; + public static function fuzzyMatchScore(key:String, fuzzySearchKey:String) { + return 1 - (key.toLowerCase().getLevenshteinDistance(fuzzySearchKey.toLowerCase()) / Math.max(key.length, fuzzySearchKey.length)); + } + function bestMatch(fuzzySearchKey:String, ?throwIfNone=true):String { if (this.exists(fuzzySearchKey)) return fuzzySearchKey; @@ -28,7 +32,7 @@ abstract FuzzyMap(StringMap) from StringMap to StringMap { var bestKey = null; for (key in this.keys()) { - var score = 1 - (key.toLowerCase().getLevenshteinDistance(fuzzySearchKey.toLowerCase()) / Math.max(key.length, fuzzySearchKey.length)); + var score = fuzzyMatchScore(key, fuzzySearchKey); if (score > bestScore) { bestScore = score; bestKey = key;