make fuzzyMatchScore public static
This commit is contained in:
@@ -21,6 +21,10 @@ abstract FuzzyMap<T>(StringMap<T>) from StringMap<T> to StringMap<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static var threshold = 0.4;
|
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 {
|
function bestMatch(fuzzySearchKey:String, ?throwIfNone=true):String {
|
||||||
if (this.exists(fuzzySearchKey)) return fuzzySearchKey;
|
if (this.exists(fuzzySearchKey)) return fuzzySearchKey;
|
||||||
|
|
||||||
@@ -28,7 +32,7 @@ abstract FuzzyMap<T>(StringMap<T>) from StringMap<T> to StringMap<T> {
|
|||||||
var bestKey = null;
|
var bestKey = null;
|
||||||
|
|
||||||
for (key in this.keys()) {
|
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) {
|
if (score > bestScore) {
|
||||||
bestScore = score;
|
bestScore = score;
|
||||||
bestKey = key;
|
bestKey = key;
|
||||||
|
Reference in New Issue
Block a user