feat(search): normalize search text (fonts, etc.)

This commit is contained in:
perf3ct 2025-08-02 23:59:45 +00:00
parent 8094259c78
commit 18f89b979d
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232

View File

@ -7,6 +7,7 @@ import Expression from "./expression.js";
import NoteSet from "../note_set.js"; import NoteSet from "../note_set.js";
import becca from "../../../becca/becca.js"; import becca from "../../../becca/becca.js";
import { normalize } from "../../utils.js"; import { normalize } from "../../utils.js";
import { normalizeSearchText } from "../utils/text_utils.js";
import beccaService from "../../../becca/becca_service.js"; import beccaService from "../../../becca/becca_service.js";
class NoteFlatTextExp extends Expression { class NoteFlatTextExp extends Expression {
@ -15,7 +16,8 @@ class NoteFlatTextExp extends Expression {
constructor(tokens: string[]) { constructor(tokens: string[]) {
super(); super();
this.tokens = tokens; // Normalize tokens using centralized normalization function
this.tokens = tokens.map(token => normalizeSearchText(token));
} }
execute(inputNoteSet: NoteSet, executionContext: any, searchContext: SearchContext) { execute(inputNoteSet: NoteSet, executionContext: any, searchContext: SearchContext) {
@ -61,8 +63,8 @@ class NoteFlatTextExp extends Expression {
} }
for (const attribute of note.getOwnedAttributes()) { for (const attribute of note.getOwnedAttributes()) {
const normalizedName = normalize(attribute.name); const normalizedName = normalizeSearchText(attribute.name);
const normalizedValue = normalize(attribute.value); const normalizedValue = normalizeSearchText(attribute.value);
for (const token of remainingTokens) { for (const token of remainingTokens) {
if (normalizedName.includes(token) || normalizedValue.includes(token)) { if (normalizedName.includes(token) || normalizedValue.includes(token)) {
@ -72,7 +74,7 @@ class NoteFlatTextExp extends Expression {
} }
for (const parentNote of note.parents) { for (const parentNote of note.parents) {
const title = normalize(beccaService.getNoteTitle(note.noteId, parentNote.noteId)); const title = normalizeSearchText(beccaService.getNoteTitle(note.noteId, parentNote.noteId));
const foundTokens: string[] = foundAttrTokens.slice(); const foundTokens: string[] = foundAttrTokens.slice();
for (const token of remainingTokens) { for (const token of remainingTokens) {
@ -108,14 +110,14 @@ class NoteFlatTextExp extends Expression {
} }
for (const attribute of note.ownedAttributes) { for (const attribute of note.ownedAttributes) {
if (normalize(attribute.name).includes(token) || normalize(attribute.value).includes(token)) { if (normalizeSearchText(attribute.name).includes(token) || normalizeSearchText(attribute.value).includes(token)) {
foundAttrTokens.push(token); foundAttrTokens.push(token);
} }
} }
} }
for (const parentNote of note.parents) { for (const parentNote of note.parents) {
const title = normalize(beccaService.getNoteTitle(note.noteId, parentNote.noteId)); const title = normalizeSearchText(beccaService.getNoteTitle(note.noteId, parentNote.noteId));
const foundTokens = foundAttrTokens.slice(); const foundTokens = foundAttrTokens.slice();
for (const token of this.tokens) { for (const token of this.tokens) {
@ -156,8 +158,9 @@ class NoteFlatTextExp extends Expression {
const candidateNotes: BNote[] = []; const candidateNotes: BNote[] = [];
for (const note of noteSet.notes) { for (const note of noteSet.notes) {
const normalizedFlatText = normalizeSearchText(note.getFlatText());
for (const token of this.tokens) { for (const token of this.tokens) {
if (note.getFlatText().includes(token)) { if (normalizedFlatText.includes(token)) {
candidateNotes.push(note); candidateNotes.push(note);
break; break;
} }