Full text search improvements

This commit is contained in:
Zef Hemel
2022-10-22 20:23:54 +02:00
parent 02dd2f17c7
commit 9164b57a3e
6 changed files with 55 additions and 15 deletions
+1 -1
View File
@@ -138,7 +138,7 @@ async function bundleRun(
console.error(`Error building ${manifestPath}:`, e);
}
}
console.log("Done.");
console.log("Done building plugs.");
building = false;
}
+21 -5
View File
@@ -1,3 +1,4 @@
import { FullTextSearchOptions } from "../../plug-api/plugos-syscall/fulltext.ts";
import { AsyncSQLite } from "../../plugos/sqlite/async_sqlite.ts";
import { SysCallMapping } from "../system.ts";
@@ -34,15 +35,30 @@ export function fullTextSearchSyscalls(
"fulltext.delete": async (_ctx, key: string) => {
await db.execute(`DELETE FROM ${tableName} WHERE key = ?`, key);
},
"fulltext.search": async (_ctx, phrase: string, limit: number) => {
console.log("Got search query", phrase);
"fulltext.search": async (
_ctx,
phrase: string,
options: FullTextSearchOptions,
) => {
return (
await db.query(
`SELECT key, rank FROM ${tableName} WHERE value MATCH ? ORDER BY key, rank LIMIT ?`,
`SELECT key, bm25(fts) AS score, snippet(fts, 1, ?, ?, ?, ?) as snippet
FROM ${tableName}
WHERE value
MATCH ?
ORDER BY score LIMIT ?`,
options.highlightPrefix || "",
options.highlightPostfix || "",
options.highlightEllipsis || "...",
options.summaryMaxLength || 50,
phrase,
limit,
options.limit || 20,
)
).map((item) => ({ name: item.key, rank: item.rank }));
).map((item) => ({
name: item.key,
score: item.score,
snippet: item.snippet,
}));
},
};
}