Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
style(search): keep the added comments to the invariant in place
sxh313ce7b71b2a77c
diff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.tsindex a8a30e2f8a..d2bb941f41 100644--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts@@ -198,12 +198,13 @@ describe("HTML entity decoding", () => {const mime = "text/html";it("makes the text the editor displays searchable", () => {- // The editor shows "if a < b && b > c, then done" for this body, and extractContentSnippet()- // decodes these same entities when it renders the hit — so a query in that shape has to match- // the body it was copied from, rather than only the entity spelling stored in the blob.- expect(preprocessContent("<p>AT&T reported earnings.</p>", type, mime)).toEqual("at&t reported earnings.");- expect(preprocessContent("<p>if a < b && b > c, then done</p>", type, mime))- .toEqual("if a < b && b > c, then done");+ // `extractContentSnippet()` decodes these entities to render a hit, so the same spelling+ // is what a query has to match.+ const entities = "<p>if a < b && b > c, then done</p>";++ expect(preprocessContent("<p>AT&T reported earnings.</p>", type, mime))+ .toEqual("at&t reported earnings.");+ expect(preprocessContent(entities, type, mime)).toEqual("if a < b && b > c, then done");});it("decodes an entity-encoded query separator inside an anchor's href", () => {@@ -213,13 +214,14 @@ describe("HTML entity decoding", () => {});it("decodes once, so a body showing an entity is still found by what it shows", () => {- // "&amp;" displays as "&", and searching for that literal string must hit it — which- // it would not if the decode ran twice and left a bare "&".- expect(preprocessContent("<p>use &amp; to write one</p>", type, mime)).toContain("use & to write one");+ // This body displays "&"; a second decode would leave a bare "&" and stop matching the+ // characters the note shows.+ expect(preprocessContent("<p>use &amp; to write one</p>", type, mime))+ .toContain("use & to write one");});it("keeps a raw content search against the stored markup", () => {- // note.rawContent is the blob as written, entities and tags included, so it stays encoded.+ // `note.rawContent` is the blob as written, entities and tags included.expect(preprocessContent("<p>AT&T</p>", type, mime, true)).toEqual("<p>at&t</p>");});});\ No newline at end of filediff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.tsindex f5a34c0c1e..1632e193f1 100644--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts@@ -20,11 +20,9 @@ export default function preprocessContent(rawContent: string | Uint8Array, type:// Content size already filtered at DB level, safe to processcontent = stripTags(content);- // What striptags leaves behind is the body as the editor writes it, so entities stand in- // for the characters on screen. Decoding them here is what makes a query copied off the- // screen match; extractContentSnippet() already decodes the same set to render the hit.- // Runs before the injected text is appended, since that one is decoded already and a- // second pass would eat an "&lt;" the note means literally.+ // The stored body holds entities where the editor shows characters, so decoding is what+ // makes the searchable text the displayed one. Injected link text arrives already+ // decoded, so this runs before it is appended and never twice over the same characters.content = unescapeHtml(content);if (injectedText) {diff --git a/packages/trilium-core/src/services/search/services/search.spec.ts b/packages/trilium-core/src/services/search/services/search.spec.tsindex 7f37d0f47c..f4b9200299 100644--- a/packages/trilium-core/src/services/search/services/search.spec.ts+++ b/packages/trilium-core/src/services/search/services/search.spec.ts@@ -1171,13 +1171,14 @@ describe("Search", () => {}function finds(query: string, noteId: string) {- return searchService.findResultsWithQuery(query, new SearchContext()).some((result) => result.noteId === noteId);+ const results = searchService.findResultsWithQuery(query, new SearchContext());++ return results.some((result) => result.noteId === noteId);}it("finds a body by the text the editor shows for it", () => {- // The editor renders this body as "AT&T reported R&D spend, where a<b held.", and that is- // the wording the quick-search snippet prints back. Searching for the words on screen found- // nothing, because only was unwrapped while &, < and > stayed encoded.+ // This body reads "AT&T reported R&D spend, where a<b held." on screen, and that is the+ // wording the result card prints back, so a query in that shape has to reach the body.const telco = bodyNote("Telco", "<p>AT&T reported R&D spend, where a<b held.</p>");expect(finds("AT&T", telco.noteId)).toBe(true);@@ -1186,8 +1187,8 @@ describe("Search", () => {});it("decodes once, so a body showing an entity is found by what it shows", () => {- // This body reads "write &t rather than <" on screen. Decoding it a second time- // would turn the shown "<" into a bare "<" and let the second query through.+ // The body displays "&" and "<". A second decode would turn the second one into+ // a bare "<", which is not what the note says.const literal = bodyNote("Literal", "<p>write &amp;t rather than &lt;</p>");expect(finds("<", literal.noteId)).toBe(true);