2025-05-12 13:37:34 +00:00
|
|
|
import * as plugins from './smartfuzzy.plugins.js';
|
2018-08-19 20:52:52 +02:00
|
|
|
|
|
|
|
export class ObjectSorter<T> {
|
|
|
|
public objectDictionary: T[];
|
|
|
|
|
|
|
|
constructor(objectDictionaryArg: T[] = []) {
|
|
|
|
this.objectDictionary = objectDictionaryArg;
|
|
|
|
}
|
|
|
|
|
2025-05-12 13:37:34 +00:00
|
|
|
sort(stringArg: string, objectKeysArg: string[]): Array<{ item: T; refIndex: number; score?: number }> {
|
2018-08-19 20:52:52 +02:00
|
|
|
const fuseOptions = {
|
|
|
|
shouldSort: true,
|
|
|
|
threshold: 0.6,
|
|
|
|
location: 0,
|
|
|
|
distance: 100,
|
|
|
|
maxPatternLength: 32,
|
|
|
|
minMatchCharLength: 1,
|
2021-10-03 17:37:03 +02:00
|
|
|
keys: objectKeysArg,
|
2018-08-19 20:52:52 +02:00
|
|
|
};
|
2021-10-03 17:12:02 +02:00
|
|
|
const fuse = new plugins.fuseJs<T>(this.objectDictionary, fuseOptions);
|
2018-08-19 20:52:52 +02:00
|
|
|
const result = fuse.search(stringArg);
|
|
|
|
return result;
|
|
|
|
}
|
2021-10-03 17:37:03 +02:00
|
|
|
}
|