feat(search): update fulltext search and add stress test improvements

- Modified note_content_fulltext.ts for enhanced search capabilities
- Updated becca_mocking.ts for better test support
- Improved stress-test-populate.ts script
This commit is contained in:
perfectra1n
2025-11-16 14:17:55 -08:00
parent 09ff9ccc65
commit 30da95d75a
3 changed files with 30 additions and 19 deletions

View File

@@ -314,13 +314,19 @@ class NoteContentFulltextExp extends Expression {
[key: string]: any; // Other properties that may exist [key: string]: any; // Other properties that may exist
} }
let canvasContent = JSON.parse(content); try {
const elements: Element[] = canvasContent.elements; let canvasContent = JSON.parse(content);
const texts = elements // Canvas content may not have elements array, use empty array as default
.filter((element: Element) => element.type === "text" && element.text) // Filter for 'text' type elements with a 'text' property const elements: Element[] = canvasContent.elements || [];
.map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering const texts = elements
.filter((element: Element) => element.type === "text" && element.text) // Filter for 'text' type elements with a 'text' property
.map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering
content = normalize(texts.toString()); content = normalize(texts.join(" "));
} catch (e) {
// Handle JSON parse errors or malformed canvas content
content = "";
}
} }
return content.trim(); return content.trim();

View File

@@ -25,7 +25,7 @@ export class NoteBuilder {
isInheritable, isInheritable,
name, name,
value value
}); }).save();
return this; return this;
} }
@@ -37,7 +37,7 @@ export class NoteBuilder {
type: "relation", type: "relation",
name, name,
value: targetNote.noteId value: targetNote.noteId
}); }).save();
return this; return this;
} }
@@ -49,7 +49,7 @@ export class NoteBuilder {
parentNoteId: this.note.noteId, parentNoteId: this.note.noteId,
prefix, prefix,
notePosition: 10 notePosition: 10
}); }).save();
return this; return this;
} }
@@ -70,7 +70,7 @@ export function note(title: string, extraParams: Partial<NoteRow> = {}) {
extraParams extraParams
); );
const note = new BNote(row); const note = new BNote(row).save();
return new NoteBuilder(note); return new NoteBuilder(note);
} }

View File

@@ -30,7 +30,6 @@ import BAttribute from "../apps/server/src/becca/entities/battribute.js";
import becca from "../apps/server/src/becca/becca.js"; import becca from "../apps/server/src/becca/becca.js";
import { NoteBuilder, id, note } from "../apps/server/src/test/becca_mocking.js"; import { NoteBuilder, id, note } from "../apps/server/src/test/becca_mocking.js";
import type { NoteType } from "@triliumnext/commons"; import type { NoteType } from "@triliumnext/commons";
import { dbReady } from "../apps/server/src/services/sql_init.js";
// Parse command line arguments // Parse command line arguments
const args = process.argv.slice(2); const args = process.argv.slice(2);
@@ -397,17 +396,23 @@ async function main() {
console.log("Initializing translations..."); console.log("Initializing translations...");
await initializeTranslations(); await initializeTranslations();
console.log("Initializing database connection...");
// Wait for database to be ready (initialized by sql.ts import)
await dbReady;
console.log("Loading becca (backend cache)..."); console.log("Loading becca (backend cache)...");
// Dynamically import becca_loader to ensure proper initialization order // Directly load becca instead of waiting for beccaLoaded promise
const { beccaLoaded } = await import("../apps/server/src/becca/becca_loader.js"); // (beccaLoaded depends on dbReady which won't resolve in this script context)
await beccaLoaded; const becca_loader = (await import("../apps/server/src/becca/becca_loader.js")).default;
const cls = (await import("../apps/server/src/services/cls.js")).default;
// Load becca and run the population inside CLS context
cls.init(() => {
becca_loader.load();
console.log("Becca loaded successfully.");
populateNotes();
});
}
function populateNotes() {
const rootNote = becca.getNote("root"); const rootNote = becca.getNote("root");
if (!rootNote) { if (!rootNote) {
throw new Error("Root note not found!"); throw new Error("Root note not found!");