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