From e7a504c66b0d5359567ba189dda5a2667705b234 Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 5 Jun 2018 22:47:47 -0400 Subject: [PATCH] fixes and optimizations for search --- src/public/javascripts/dialogs/jump_to_note.js | 6 ++++++ src/public/javascripts/services/tree_builder.js | 9 ++++++++- src/routes/api/autocomplete.js | 2 +- src/services/note_cache.js | 5 +++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/public/javascripts/dialogs/jump_to_note.js b/src/public/javascripts/dialogs/jump_to_note.js index 906b929d7..5059426f1 100644 --- a/src/public/javascripts/dialogs/jump_to_note.js +++ b/src/public/javascripts/dialogs/jump_to_note.js @@ -24,6 +24,12 @@ async function showDialog() { }, minLength: 2 }); + + $autoComplete.autocomplete("instance")._renderItem = function(ul, item) { + return $("
  • ") + .append("
    " + item.label + "
    ") + .appendTo(ul); + }; } function getSelectedNotePath() { diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.js index 813233c5c..c257433f8 100644 --- a/src/public/javascripts/services/tree_builder.js +++ b/src/public/javascripts/services/tree_builder.js @@ -76,12 +76,19 @@ async function prepareSearchBranch(note) { const fullNote = await noteDetailService.loadNote(note.noteId); const results = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString)); + const noteIds = results.map(res => res.noteId); + + // force to load all the notes at once instead of one by one + await treeCache.getNotes(noteIds); + for (const result of results) { + const origBranch = await treeCache.getBranch(result.branchId); + const branch = new Branch(treeCache, { branchId: "virt" + utils.randomString(10), noteId: result.noteId, parentNoteId: note.noteId, - prefix: result.prefix, + prefix: origBranch.prefix, virtual: true }); diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index 922c3e84b..424a940f8 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -10,7 +10,7 @@ async function getAutocomplete(req) { return results.map(res => { return { value: res.title + ' (' + res.path + ')', - title: res.title + label: res.title } }); } diff --git a/src/services/note_cache.js b/src/services/note_cache.js index cf284c796..34223834b 100644 --- a/src/services/note_cache.js +++ b/src/services/note_cache.js @@ -100,8 +100,7 @@ function search(noteId, tokens, path, results) { noteId: thisNoteId, branchId: childParentToBranchId[`${thisNoteId}-${thisParentNoteId}`], title: noteTitle, - path: retPath.join('/'), - prefix: prefixes[`${thisNoteId}-${thisParentNoteId}`] + path: retPath.join('/') }); } @@ -206,9 +205,11 @@ function getNotePath(noteId) { if (retPath) { const noteTitle = getNoteTitleForPath(retPath); + const parentNoteId = childToParent[noteId][0]; return { noteId: noteId, + branchId: childParentToBranchId[`${noteId}-${parentNoteId}`], title: noteTitle, path: retPath.join('/') };