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
allow searching with noteId & fix combining fulltext and other conditions with OR
zadam5bda2541847f
diff --git a/src/services/build_search_query.js b/src/services/build_search_query.jsindex cfdab626c9..f81a6ff334 100644--- a/src/services/build_search_query.js+++ b/src/services/build_search_query.js@@ -5,6 +5,7 @@ const VIRTUAL_ATTRIBUTES = ["dateModified","utcDateCreated","utcDateModified",+ "noteId","isProtected","title","content",@@ -37,20 +38,11 @@ module.exports = function(filters, selectedColumns = 'notes.*') {const alias = "note_contents";if (!(alias in joins)) {- joins[alias] = `JOIN note_contents ON note_contents.noteId = notes.noteId`;+ joins[alias] = `LEFT JOIN note_contents ON note_contents.noteId = notes.noteId`;}accessor = `${alias}.${property}`;}- else if (property === 'text') {- const alias = "note_fulltext";-- if (!(alias in joins)) {- joins[alias] = `JOIN note_fulltext ON note_fulltext.noteId = notes.noteId`;- }-- accessor = alias;- }else {accessor = "notes." + property;}@@ -92,17 +84,11 @@ module.exports = function(filters, selectedColumns = 'notes.*') {else if (filter.operator === '=' || filter.operator === '!=') {if (filter.name === 'text') {const safeSearchText = utils.sanitizeSql(filter.value);- let condition = accessor + ' ' + `MATCH '${safeSearchText}'`;-- if (filter.operator.includes("!")) {- // not supported!- }- else if (orderBy.length === 0) {- // if there's a positive full text search and there's no defined order then order by rank- orderBy.push("rank");- }+ const not = filter.operator.includes("!") ? "NOT" : "";- where += condition;+ // fulltext needs to use subselect because fulltext doesn't support OR operations at all+ // which makes it impossible to combine more operations together+ where += `notes.noteId ${not} IN (SELECT noteId FROM note_fulltext WHERE note_fulltext MATCH '${safeSearchText}')`;}else {where += `${accessor} ${filter.operator} ?`;diff --git a/src/services/parse_filters.js b/src/services/parse_filters.jsindex 6b53d06da6..0ae1bba170 100644--- a/src/services/parse_filters.js+++ b/src/services/parse_filters.js@@ -51,6 +51,12 @@ module.exports = function (searchText) {name: 'text',operator: '=',value: searchText+ },+ {+ relation: 'or',+ name: 'noteId',+ operator: '=',+ value: searchText}]}diff --git a/src/services/protected_session.js b/src/services/protected_session.jsindex fac3697966..d79002b635 100644--- a/src/services/protected_session.js+++ b/src/services/protected_session.js@@ -91,7 +91,7 @@ function decryptNoteRevision(hist) {}}catch (e) {- throw new Error(`Decryption failed for note ${hist.noteId}: ` + e.message + " " + e.stack);+ throw new Error(`Decryption failed for note ${hist.noteId}, revision ${hist.noteRevisionId}: ` + e.message + " " + e.stack);}}