A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
918 B

import { SearchService } from "./SearchService";
// import * as Fuse from 'fuse.js';
import Fuse = require('fuse.js');
export class FuseSearchService<T> implements SearchService<T> {
// private readonly _fuse: Fuse<T, Object>;
private readonly _params: Fuse.FuseOptions<T>;
constructor(keys: string[], params: Fuse.FuseOptions<T> = {
shouldSort: true,
threshold: 0.01,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
// keys: [
// "userName",
// ]
}) {
this._params = params;
this._params.keys = keys;
// this._fuse = new Fuse(list, this._params);
}
search<T>(list: T[], searchTerm: string): T[] {
const fuse = new Fuse<T, Fuse.FuseOptions<any>>(list, this._params);
// fuse.search(searchTerm);
return fuse.search(searchTerm) as T[];
}
}