mirror of
https://github.com/zadam/trilium.git
synced 2025-01-17 20:48:12 +08:00
fixed saved search refresh
This commit is contained in:
parent
053162fef2
commit
f8089ba370
4 changed files with 15 additions and 19 deletions
|
@ -75,7 +75,7 @@ class TreeCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
note.children = [];
|
note.children = [];
|
||||||
note.childToBranch = [];
|
note.childToBranch = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// we want to remove all "real" branches (represented in the database) since those will be created
|
// 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);
|
this.addResp(resp);
|
||||||
|
|
||||||
const searchNoteIds = [];
|
|
||||||
|
|
||||||
for (const note of resp.notes) {
|
for (const note of resp.notes) {
|
||||||
if (note.type === 'search') {
|
if (note.type === 'search') {
|
||||||
searchNoteIds.push(note.noteId);
|
|
||||||
|
|
||||||
const searchResultNoteIds = await server.get('search-note/' + note.noteId);
|
const searchResultNoteIds = await server.get('search-note/' + note.noteId);
|
||||||
|
|
||||||
if (!Array.isArray(searchResultNoteIds)) {
|
if (!Array.isArray(searchResultNoteIds)) {
|
||||||
|
@ -182,13 +178,14 @@ class TreeCache {
|
||||||
// reset all the virtual branches from old search results
|
// reset all the virtual branches from old search results
|
||||||
if (note.noteId in treeCache.notes) {
|
if (note.noteId in treeCache.notes) {
|
||||||
treeCache.notes[note.noteId].children = [];
|
treeCache.notes[note.noteId].children = [];
|
||||||
|
treeCache.notes[note.noteId].childToBranch = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId);
|
const branches = resp.branches.filter(b => b.noteId === note.noteId || b.parentNoteId === note.noteId);
|
||||||
|
|
||||||
searchResultNoteIds.forEach((resultNoteId, index) => branches.push({
|
searchResultNoteIds.forEach((resultNoteId, index) => branches.push({
|
||||||
// branchId should be repeatable since sometimes we reload some notes without rerendering the tree
|
// 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,
|
noteId: resultNoteId,
|
||||||
parentNoteId: note.noteId,
|
parentNoteId: note.noteId,
|
||||||
notePosition: (index + 1) * 10,
|
notePosition: (index + 1) * 10,
|
||||||
|
@ -204,9 +201,7 @@ class TreeCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchNoteIds.length > 0) {
|
appContext.triggerEvent('notesReloaded', {noteIds});
|
||||||
appContext.triggerEvent('searchResultsUpdated', {searchNoteIds});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {NoteShort[]} */
|
/** @return {NoteShort[]} */
|
||||||
|
|
|
@ -46,8 +46,8 @@ export default class NoteListWidget extends TabAwareWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
searchResultsUpdatedEvent({searchNoteIds}) {
|
notesReloadedEvent({noteIds}) {
|
||||||
if (searchNoteIds.includes(this.noteId)) {
|
if (noteIds.includes(this.noteId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,12 @@ async function searchFromNote(req) {
|
||||||
return [400, `Note ${req.params.noteId} is not search note.`]
|
return [400, `Note ${req.params.noteId} is not search note.`]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let searchString;
|
||||||
let searchResultNoteIds;
|
let searchResultNoteIds;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const searchScript = note.getRelationValue('searchScript');
|
const searchScript = note.getRelationValue('searchScript');
|
||||||
const searchString = note.getLabelValue('searchString');
|
searchString = note.getLabelValue('searchString');
|
||||||
|
|
||||||
if (searchScript) {
|
if (searchScript) {
|
||||||
searchResultNoteIds = await searchFromRelation(note, 'searchScript');
|
searchResultNoteIds = await searchFromRelation(note, 'searchScript');
|
||||||
|
@ -60,6 +61,8 @@ async function searchFromNote(req) {
|
||||||
searchResultNoteIds = searchResultNoteIds.slice(0, 200);
|
searchResultNoteIds = searchResultNoteIds.slice(0, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Search with query "${searchString}" with results: ${searchResultNoteIds}`);
|
||||||
|
|
||||||
return searchResultNoteIds;
|
return searchResultNoteIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,15 +90,13 @@ function findNotesWithQuery(query, searchContext) {
|
||||||
|
|
||||||
searchContext.originalQuery = query;
|
searchContext.originalQuery = query;
|
||||||
|
|
||||||
return utils.stopWatch(`Search with query "${query}"`, () => {
|
const expression = parseQueryToExpression(query, searchContext);
|
||||||
const expression = parseQueryToExpression(query, searchContext);
|
|
||||||
|
|
||||||
if (!expression) {
|
if (!expression) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return findNotesWithExpression(expression, searchContext);
|
return findNotesWithExpression(expression, searchContext);
|
||||||
}, 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchTrimmedNotes(query, searchContext) {
|
function searchTrimmedNotes(query, searchContext) {
|
||||||
|
|
Loading…
Reference in a new issue