Fixes #90: Re-enables full text search

This commit is contained in:
Zef Hemel
2022-10-19 09:52:29 +02:00
parent e225c926f5
commit 70501bc3e4
13 changed files with 128 additions and 80 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import type { SysCallMapping } from "../system.ts";
import { mime, path } from "../deps.ts";
import { base64Decode, base64Encode } from "../asset_bundle/base64.ts";
import { base64DecodeDataUrl, base64Encode } from "../asset_bundle/base64.ts";
import { FileMeta } from "../../common/types.ts";
export default function fileSystemSyscalls(root = "/"): SysCallMapping {
@@ -51,7 +51,7 @@ export default function fileSystemSyscalls(root = "/"): SysCallMapping {
if (encoding === "utf8") {
await Deno.writeTextFile(p, text);
} else {
await Deno.writeFile(p, base64Decode(text.split(",")[1]));
await Deno.writeFile(p, base64DecodeDataUrl(text));
}
const s = await Deno.stat(p);
return {
+12 -16
View File
@@ -2,27 +2,22 @@ import { SQLite } from "../../server/deps.ts";
import { SysCallMapping } from "../system.ts";
import { asyncExecute, asyncQuery } from "./store.deno.ts";
type Item = {
key: string;
value: string;
};
export function ensureFTSTable(
db: SQLite,
tableName: string,
) {
// const stmt = db.prepare(
// `SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
// );
// const result = stmt.all(tableName);
// if (result.length === 0) {
// asyncExecute(
// db,
// `CREATE VIRTUAL TABLE ${tableName} USING fts5(key, value);`,
// );
const result = db.query(
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
[tableName],
);
if (result.length === 0) {
asyncExecute(
db,
`CREATE VIRTUAL TABLE ${tableName} USING fts5(key, value);`,
);
// console.log(`Created fts5 table ${tableName}`);
// }
console.log(`Created fts5 table ${tableName}`);
}
return Promise.resolve();
}
@@ -44,6 +39,7 @@ export function fullTextSearchSyscalls(
await asyncExecute(db, `DELETE FROM ${tableName} WHERE key = ?`, key);
},
"fulltext.search": async (_ctx, phrase: string, limit: number) => {
console.log("Got search query", phrase);
return (
await asyncQuery<any>(
db,