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
improvements to saved search
zadama68c61b2f0ca
diff --git a/db/migrations/0172__migrate_saved_notes.js b/db/migrations/0172__migrate_saved_notes.jsnew file mode 100644index 0000000000..833fba3854--- /dev/null+++ b/db/migrations/0172__migrate_saved_notes.js@@ -0,0 +1,23 @@+const repository = require('../../src/services/repository');++module.exports = () => {+ for (const note of repository.getEntities("SELECT * FROM notes WHERE type = 'search' AND isProtected = 0 AND isDeleted = 0")) {+ try {+ let origContent = note.getJsonContent();++ if (!origContent) {+ continue;+ }++ note.addLabel('searchString', origContent.searchString);++ note.setContent('');++ note.mime = 'text/plain';+ note.save();+ }+ catch (e) {+ console.log(`Changing note content for note ${note.noteId} failed with: ${e.message} ${e.stack}`);+ }+ }+};diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.jsindex dd87112525..21bd45d62c 100644--- a/src/public/app/services/note_list_renderer.js+++ b/src/public/app/services/note_list_renderer.js@@ -152,7 +152,8 @@ class NoteListRenderer {this.viewType = parentNote.getLabelValue('viewType');if (!['list', 'grid'].includes(this.viewType)) {- this.viewType = 'list'; // default+ // when not explicitly set decide based on note type+ this.viewType = parentNote.type === 'search' ? 'list' : 'grid';}this.$noteList.addClass(this.viewType + '-view');diff --git a/src/public/app/widgets/note_list.js b/src/public/app/widgets/note_list.jsindex c5a418eb88..c821ab1902 100644--- a/src/public/app/widgets/note_list.js+++ b/src/public/app/widgets/note_list.js@@ -32,15 +32,6 @@ export default class NoteListWidget extends TabAwareWidget {}async refreshWithNote(note) {- // this.tabContext.autoBookDisabled;- //- // const noteComplement = await this.tabContext.getNoteComplement();- //- // if (utils.isHtmlEmpty(noteComplement.content)) {- //- // }- //-const noteListRenderer = new NoteListRenderer(note, note.getChildNoteIds());this.$content.empty().append(await noteListRenderer.renderList());diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex 696383cd23..ee593f8e9b 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -131,8 +131,7 @@ const TPL = `}.tree-item-button {- font-size: 120%;- padding: 2px;+ font-size: 130%;cursor: pointer;border-radius: 3px;border: 1px solid var(--main-background-color);diff --git a/src/public/app/widgets/search_definition.js b/src/public/app/widgets/search_definition.jsindex 1b9dce8041..09f3f0ad22 100644--- a/src/public/app/widgets/search_definition.js+++ b/src/public/app/widgets/search_definition.js@@ -110,9 +110,8 @@ export default class SearchDefinitionWidget extends TabAwareWidget {await treeCache.reloadNotes([this.noteId]);}- async doRefresh(note) {+ async refreshWithNote(note) {this.$component.show();-this.$searchString.val(this.note.getLabelValue('searchString'));this.$searchWithinNoteContent.prop('checked', this.note.getLabelValue('includeNoteContent') === 'true');this.$limitSearchToSubtree.val(this.note.getLabelValue('subTreeNoteId'));diff --git a/src/routes/api/search.js b/src/routes/api/search.jsindex 4032ffc44f..53bbcd226c 100644--- a/src/routes/api/search.js+++ b/src/routes/api/search.js@@ -46,16 +46,16 @@ async function searchFromNote(req) {return [400, `Note ${req.params.noteId} is not search note.`]}- const searchString = note.getLabelValue('searchString');-let searchResultNoteIds;try {- if (searchString.startsWith('=')) {- const relationName = searchString.substr(1).trim();+ const searchScript = note.getRelationValue('searchScript');+ const searchString = note.getLabelValue('searchString');- searchResultNoteIds = await searchFromRelation(note, relationName);- } else {+ if (searchScript) {+ searchResultNoteIds = await searchFromRelation(note, 'searchScript');+ }+ else if (searchString) {const searchContext = new SearchContext({includeNoteContent: note.getLabelValue('includeNoteContent') === 'true',excludeArchived: true,@@ -65,6 +65,9 @@ async function searchFromNote(req) {searchResultNoteIds = searchService.findNotesWithQuery(searchString, searchContext).map(sr => sr.noteId);}+ else {+ searchResultNoteIds = [];+ }}catch (e) {log.error(`Search failed for note ${note.noteId}: ` + e.message + ": " + e.stack);diff --git a/src/services/app_info.js b/src/services/app_info.jsindex fc8fa27bac..2d1bce3143 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 = 171;+const APP_DB_VERSION = 172;const SYNC_VERSION = 16;const CLIPPER_PROTOCOL_VERSION = "1.0";