Skip to content

Build your personal knowledge base with Trilium Notes

search note content only if not excluded by other expressions

zadame89057a771a7
diff --git a/src/services/search/expressions/note_content_protected_fulltext.js b/src/services/search/expressions/note_content_protected_fulltext.js
index daed140002..0ed21eb158 100644
--- a/src/services/search/expressions/note_content_protected_fulltext.js
+++ b/src/services/search/expressions/note_content_protected_fulltext.js
@@ -32,11 +32,15 @@ class NoteContentProtectedFulltextExp extends Expression {
FROM notes JOIN note_contents USING (noteId)
WHERE type IN ('text', 'code') AND isDeleted = 0 AND isProtected = 1`)) {
+ if (!inputNoteSet.hasNoteId(noteId) || !(noteId in noteCache.notes)) {
+ continue;
+ }
+
try {
content = protectedSessionService.decryptString(content);
}
catch (e) {
- log.info('Cannot decrypt content of note', noteId);
+ log.info(`Cannot decrypt content of note ${noteId}`);
continue;
}
@@ -50,11 +54,7 @@ class NoteContentProtectedFulltextExp extends Expression {
content = content.replace(/ /g, ' ');
}
- if (this.tokens.find(token => !content.includes(token))) {
- continue;
- }
-
- if (inputNoteSet.hasNoteId(noteId) && noteId in noteCache.notes) {
+ if (!this.tokens.find(token => !content.includes(token))) {
resultNoteSet.add(noteCache.notes[noteId]);
}
}
diff --git a/src/services/search/expressions/note_content_unprotected_fulltext.js b/src/services/search/expressions/note_content_unprotected_fulltext.js
index ad0ce7cdfa..a9a531269c 100644
--- a/src/services/search/expressions/note_content_unprotected_fulltext.js
+++ b/src/services/search/expressions/note_content_unprotected_fulltext.js
@@ -26,6 +26,10 @@ class NoteContentUnprotectedFulltextExp extends Expression {
FROM notes JOIN note_contents USING (noteId)
WHERE type IN ('text', 'code') AND isDeleted = 0 AND isProtected = 0`)) {
+ if (!inputNoteSet.hasNoteId(noteId) || !(noteId in noteCache.notes)) {
+ continue;
+ }
+
content = content.toString().toLowerCase();
if (type === 'text' && mime === 'text/html') {
@@ -36,11 +40,7 @@ class NoteContentUnprotectedFulltextExp extends Expression {
content = content.replace(/ /g, ' ');
}
- if (this.tokens.find(token => !content.includes(token))) {
- continue;
- }
-
- if (inputNoteSet.hasNoteId(noteId) && noteId in noteCache.notes) {
+ if (!this.tokens.find(token => !content.includes(token))) {
resultNoteSet.add(noteCache.notes[noteId]);
}
}