generated from silverbulletmd/silverbullet-plug-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch.ts
More file actions
21 lines (18 loc) · 815 Bytes
/
search.ts
File metadata and controls
21 lines (18 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import type { IndexTreeEvent } from "@silverbulletmd/silverbullet/type/event";
import { renderToText } from "@silverbulletmd/silverbullet/lib/tree";
import { system } from "@silverbulletmd/silverbullet/syscalls";
import { ftsIndexPage } from "./engine.ts";
import { PromiseQueue } from "@silverbulletmd/silverbullet/lib/async";
// Search indexing is prone to concurrency issues, so we queue all write operations
const promiseQueue = new PromiseQueue();
export async function indexPage({ name, tree }: IndexTreeEvent) {
if (!await system.getConfig("index.search.enabled", true)) {
return;
}
const text = renderToText(tree);
return promiseQueue.runInQueue(async () => {
// console.log("Now FTS indexing", name);
// await engine.deleteDocument(name);
await ftsIndexPage(name, text);
});
}