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
refactoring for archived notes handling in note cache
zadam69e36d267798
diff --git a/db/migrations/0168__rename_hideInAutocomplete_to_archived.sql b/db/migrations/0168__rename_hideInAutocomplete_to_archived.sqlnew file mode 100644index 0000000000..29b72138c2--- /dev/null+++ b/db/migrations/0168__rename_hideInAutocomplete_to_archived.sql@@ -0,0 +1 @@+UPDATE attributes SET name = 'archived' WHERE name = 'hideInAutocomplete';diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.jsindex b0d8e1df2b..a58d03ce9d 100644--- a/src/routes/api/clipper.js+++ b/src/routes/api/clipper.js@@ -113,8 +113,8 @@ function addImagesToNote(images, note, content) {new Attribute({noteId: imageNote.noteId,type: 'label',- name: 'hideInAutocomplete'- }).save();+ name: 'archived'+ }).save(); // so that these image notes don't show up in search / autocompletenew Attribute({noteId: note.noteId,diff --git a/src/services/app_info.js b/src/services/app_info.jsindex 0771d26005..89a95ed9e8 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -4,7 +4,7 @@ const build = require('./build');const packageJson = require('../../package');const {TRILIUM_DATA_DIR} = require('./data_dir');-const APP_DB_VERSION = 167;+const APP_DB_VERSION = 168;const SYNC_VERSION = 16;const CLIPPER_PROTOCOL_VERSION = "1.0";diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.jsindex 9f8c5b4833..7c39dd4ffd 100644--- a/src/services/note_cache/entities/note.js+++ b/src/services/note_cache/entities/note.js@@ -138,12 +138,6 @@ class Note {return this.hasAttribute('label', 'archived');}- get isHideInAutocompleteOrArchived() {- return this.attributes.find(attr =>- attr.type === 'label'- && ["archived", "hideInAutocomplete"].includes(attr.name));- }-get hasInheritableOwnedArchivedLabel() {return !!this.ownedAttributes.find(attr => attr.type === 'label' && attr.name === 'archived' && attr.isInheritable);}@@ -155,20 +149,19 @@ class Note {}/**- * @return {string} - returns flattened textual representation of note, prefixes and attributes usable for searching+ * This is used for:+ * - fast searching+ * - note similarity evaluation+ *+ * @return {string} - returns flattened textual representation of note, prefixes and attributes*/get flatText() {if (!this.flatTextCache) {- if (this.isHideInAutocompleteOrArchived) {- this.flatTextCache = " "; // can't be empty- return this.flatTextCache;- }-- this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime;+ this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime + ' ';for (const branch of this.parentBranches) {if (branch.prefix) {- this.flatTextCache += branch.prefix + ' - ';+ this.flatTextCache += branch.prefix + ' ';}}@@ -176,11 +169,13 @@ class Note {for (const attr of this.attributes) {// it's best to use space as separator since spaces are filtered from the search string by the tokenization into words- this.flatTextCache += ' ' + (attr.type === 'label' ? '#' : '@') + attr.name;+ this.flatTextCache += (attr.type === 'label' ? '#' : '~') + attr.name;if (attr.value) {this.flatTextCache += '=' + attr.value;}++ this.flatTextCache += ' ';}this.flatTextCache = this.flatTextCache.toLowerCase();diff --git a/src/services/note_cache/note_cache_service.js b/src/services/note_cache/note_cache_service.jsindex 234d6ed172..a586a8bc88 100644--- a/src/services/note_cache/note_cache_service.js+++ b/src/services/note_cache/note_cache_service.js@@ -177,7 +177,7 @@ function getNotePath(noteId) {function evaluateSimilarity(sourceNote, candidateNote, results) {let coeff = stringSimilarity.compareTwoStrings(sourceNote.flatText, candidateNote.flatText);- if (coeff > 0.4) {+ if (coeff > 0.5) {const notePath = getSomePath(candidateNote);// this takes care of note hoisting@@ -214,7 +214,7 @@ function findSimilarNotes(noteId) {}for (const note of Object.values(noteCache.notes)) {- if (note.isProtected && !note.isDecrypted) {+ if (note.noteId === origNote.noteId) {continue;}diff --git a/src/services/search/parsing_context.js b/src/services/search/parsing_context.jsindex 7867ed186c..93bf6d9235 100644--- a/src/services/search/parsing_context.js+++ b/src/services/search/parsing_context.js@@ -3,6 +3,7 @@class ParsingContext {constructor(params = {}) {this.includeNoteContent = !!params.includeNoteContent;+ this.excludeArchived = !!params.excludeArchived;this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;this.highlightedTokens = [];this.originalQuery = "";diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.jsindex 91f7baa996..29b9a699b9 100644--- a/src/services/search/services/parse.js+++ b/src/services/search/services/parse.js@@ -27,23 +27,16 @@ function getFulltext(tokens, parsingContext) {return null;}- let textSearchExpression;-if (parsingContext.includeNoteContent) {- textSearchExpression = new OrExp([+ return new OrExp([new NoteCacheFulltextExp(tokens),new NoteContentProtectedFulltextExp('*=*', tokens),new NoteContentUnprotectedFulltextExp('*=*', tokens)]);}else {- textSearchExpression = new NoteCacheFulltextExp(tokens);+ return new NoteCacheFulltextExp(tokens);}-- return new AndExp([- textSearchExpression,- new PropertyComparisonExp("isarchived", buildComparator("=", "false"))- ]);}function isOperator(str) {@@ -399,6 +392,7 @@ function getExpression(tokens, parsingContext, level = 0) {function parse({fulltextTokens, expressionTokens, parsingContext}) {return AndExp.of([+ parsingContext.excludeArchived ? new PropertyComparisonExp("isarchived", buildComparator("=", "false")) : null,getFulltext(fulltextTokens, parsingContext),getExpression(expressionTokens, parsingContext)]);diff --git a/src/services/search/services/search.js b/src/services/search/services/search.jsindex d10cf86829..67f421ddba 100644--- a/src/services/search/services/search.js+++ b/src/services/search/services/search.js@@ -91,6 +91,7 @@ function searchNotes(query) {const parsingContext = new ParsingContext({includeNoteContent: true,+ excludeArchived: true,fuzzyAttributeSearch: false});@@ -114,6 +115,7 @@ function searchNotesForAutocomplete(query) {const parsingContext = new ParsingContext({includeNoteContent: false,+ excludeArchived: true,fuzzyAttributeSearch: true});