fix(Smartfuzzy.getClosestMatchForString() now returns the cloesest string directly): update

This commit is contained in:
Philipp Kunz 2018-08-20 00:49:01 +02:00
parent 6da6c6cca9
commit a2d8f9575d

View File

@ -34,7 +34,7 @@ export class Smartfuzzy {
return dictionaryMap;
}
getClosestMatchForString(stringArg: string) {
getClosestMatchForString(stringArg: string): string {
const fuseDictionary: { name: string }[] = [];
for (const wordArg of this.dictionary) {
fuseDictionary.push({
@ -51,7 +51,11 @@ export class Smartfuzzy {
keys: ['name']
};
const fuse = new plugins.fuseJs(fuseDictionary, fuseOptions);
const result = fuse.search(stringArg);
return result;
const fuzzyResult = fuse.search(stringArg);
let closestMatch: string = null;
if(fuzzyResult.length > 0) {
closestMatch = fuzzyResult[0].name;
}
return closestMatch;
}
}