fixed saved search refresh

This commit is contained in:
zadam 2020-12-17 21:19:52 +01:00
parent 053162fef2
commit f8089ba370
4 changed files with 15 additions and 19 deletions

View file

@ -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[]} */

View file

@ -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();
}
}

View file

@ -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;
}

View file

@ -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) {