redoc/src/services/SearchStore.ts

31 lines
668 B
TypeScript
Raw Normal View History

2018-02-22 19:48:50 +03:00
import { OperationModel } from './models';
2018-02-08 19:41:02 +03:00
import worker from './SearchWorker.worker';
2018-02-22 19:48:50 +03:00
import { IMenuItem } from './MenuStore';
2018-02-08 19:41:02 +03:00
export class SearchStore {
searchWorker = new worker();
2018-02-22 19:48:50 +03:00
constructor() {}
2018-02-08 19:41:02 +03:00
2018-02-22 19:48:50 +03:00
indexItems(groups: Array<IMenuItem | OperationModel>) {
2018-02-08 19:41:02 +03:00
groups.forEach(group => {
if (group.type !== 'group') {
this.add(group.name, group.description || '', group.id);
}
2018-02-22 19:48:50 +03:00
this.indexItems(group.items);
2018-02-08 19:41:02 +03:00
});
}
add(title: string, body: string, ref: string) {
this.searchWorker.add(title, body, ref);
}
done() {
this.searchWorker.done();
}
search(q: string) {
return this.searchWorker.search(q);
}
}