changed fuse search service to not create a new fuse object every time the search method is called
This commit is contained in:
parent
70f0ea8054
commit
e40e1a5c7a
@ -3,7 +3,7 @@ import { SearchService } from "./SearchService";
|
||||
import Fuse = require('fuse.js');
|
||||
|
||||
export class FuseSearchService<T> implements SearchService<T> {
|
||||
// private readonly _fuse: Fuse<T, Object>;
|
||||
private readonly _fuse: Fuse<T, Object>;
|
||||
private readonly _params: Fuse.FuseOptions<T>;
|
||||
|
||||
constructor(keys: string[], params: Fuse.FuseOptions<T> = {
|
||||
@ -19,13 +19,14 @@ export class FuseSearchService<T> implements SearchService<T> {
|
||||
}) {
|
||||
this._params = params;
|
||||
this._params.keys = keys;
|
||||
// this._fuse = new Fuse(list, this._params);
|
||||
this._fuse = new Fuse([], this._params);
|
||||
}
|
||||
|
||||
search<T>(list: T[], searchTerm: string): T[] {
|
||||
const fuse = new Fuse<T, Fuse.FuseOptions<any>>(list, this._params);
|
||||
search(list: T[], searchTerm: string): T[] {
|
||||
// const fuse = new Fuse<T, Fuse.FuseOptions<any>>(list, this._params);
|
||||
this._fuse.setCollection(list);
|
||||
// fuse.search(searchTerm);
|
||||
return fuse.search(searchTerm) as T[];
|
||||
return this._fuse.search(searchTerm) as T[];
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
export interface SearchService<T> {
|
||||
search<T>(list: T[], pattern: string): T[];
|
||||
search(list: T[], pattern: string): T[];
|
||||
}
|
Loading…
Reference in New Issue
Block a user