Skip to content

Build your personal knowledge base with Trilium Notes

fixed saved search refresh

zadamf8089ba3706b
diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js
index d68b9d17ee..97a217be14 100644
--- a/src/public/app/services/tree_cache.js
+++ b/src/public/app/services/tree_cache.js
@@ -75,7 +75,7 @@ class TreeCache {
}
note.children = [];
- note.childToBranch = [];
+ note.childToBranch = {};
}
// we want to remove all "real" branches (represented in the database) since those will be created
@@ -164,12 +164,8 @@ class TreeCache {
this.addResp(resp);
- const searchNoteIds = [];
-
for (const note of resp.notes) {
if (note.type === 'search') {
- searchNoteIds.push(note.noteId);
-
const searchResultNoteIds = await server.get('search-note/' + note.noteId);
if (!Array.isArray(searchResultNoteIds)) {
@@ -182,13 +178,14 @@ class TreeCache {
// reset all the virtual branches from old search results
if (note.noteId in treeCache.notes) {
treeCache.notes[note.noteId].children = [];
+ treeCache.notes[note.noteId].childToBranch = {};
}
const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId);
searchResultNoteIds.forEach((resultNoteId, index) => branches.push({
// branchId should be repeatable since sometimes we reload some notes without rerendering the tree
- branchId: "virt" + resultNoteId + '-' + note.noteId,
+ branchId: "virt-" + note.noteId + '-' + resultNoteId,
noteId: resultNoteId,
parentNoteId: note.noteId,
notePosition: (index + 1) * 10,
@@ -204,9 +201,7 @@ class TreeCache {
}
}
- if (searchNoteIds.length > 0) {
- appContext.triggerEvent('searchResultsUpdated', {searchNoteIds});
- }
+ appContext.triggerEvent('notesReloaded', {noteIds});
}
/** @return {NoteShort[]} */
diff --git a/src/public/app/widgets/note_list.js b/src/public/app/widgets/note_list.js
index cabf5088f7..fe4048de73 100644
--- a/src/public/app/widgets/note_list.js
+++ b/src/public/app/widgets/note_list.js
@@ -46,8 +46,8 @@ export default class NoteListWidget extends TabAwareWidget {
}
}
- searchResultsUpdatedEvent({searchNoteIds}) {
- if (searchNoteIds.includes(this.noteId)) {
+ notesReloadedEvent({noteIds}) {
+ if (noteIds.includes(this.noteId)) {
this.refresh();
}
}
diff --git a/src/routes/api/search.js b/src/routes/api/search.js
index c24067c935..373d7e2f46 100644
--- a/src/routes/api/search.js
+++ b/src/routes/api/search.js
@@ -22,11 +22,12 @@ async function searchFromNote(req) {
return [400, `Note ${req.params.noteId} is not search note.`]
}
+ let searchString;
let searchResultNoteIds;
try {
const searchScript = note.getRelationValue('searchScript');
- const searchString = note.getLabelValue('searchString');
+ searchString = note.getLabelValue('searchString');
if (searchScript) {
searchResultNoteIds = await searchFromRelation(note, 'searchScript');
@@ -60,6 +61,8 @@ async function searchFromNote(req) {
searchResultNoteIds = searchResultNoteIds.slice(0, 200);
}
+ console.log(`Search with query "${searchString}" with results: ${searchResultNoteIds}`);
+
return searchResultNoteIds;
}
diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js
index f49165d150..6f3afdec6b 100644
--- a/src/services/search/services/search.js
+++ b/src/services/search/services/search.js
@@ -90,15 +90,13 @@ function findNotesWithQuery(query, searchContext) {
searchContext.originalQuery = query;
- return utils.stopWatch(`Search with query "${query}"`, () => {
- const expression = parseQueryToExpression(query, searchContext);
+ const expression = parseQueryToExpression(query, searchContext);
- if (!expression) {
- return [];
- }
+ if (!expression) {
+ return [];
+ }
- return findNotesWithExpression(expression, searchContext);
- }, 20);
+ return findNotesWithExpression(expression, searchContext);
}
function searchTrimmedNotes(query, searchContext) {