From e2b8dfe96adb11acaa0db2e9f9ac531aed10bd7f Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 28 Feb 2023 23:23:48 +0100 Subject: [PATCH] fix autocomplete showing hidden paths, closes #3654 --- .../search/expressions/note_flat_text.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js index 67aae1b83..863573a13 100644 --- a/src/services/search/expressions/note_flat_text.js +++ b/src/services/search/expressions/note_flat_text.js @@ -28,15 +28,20 @@ class NoteFlatTextExp extends Expression { if (retPath) { const noteId = retPath[retPath.length - 1]; - executionContext.noteIdToNotePath[noteId] = retPath; - resultNoteSet.add(becca.notes[noteId]); + if (!resultNoteSet.hasNoteId(noteId)) { + // we could get here from multiple paths, the first one wins because the paths + // are sorted by importance + executionContext.noteIdToNotePath[noteId] = retPath; + + resultNoteSet.add(becca.notes[noteId]); + } } return; } - if (!note.parents.length === 0 || note.noteId === 'root') { + if (note.parents.length === 0 || note.noteId === 'root') { return; } @@ -49,9 +54,11 @@ class NoteFlatTextExp extends Expression { } for (const attribute of note.ownedAttributes) { + const normalizedName = utils.normalize(attribute.name); + const normalizedValue = utils.normalize(attribute.value); + for (const token of tokens) { - if (utils.normalize(attribute.name).includes(token) - || utils.normalize(attribute.value).includes(token)) { + if (normalizedName.includes(token) || normalizedValue.includes(token)) { foundAttrTokens.push(token); } } @@ -70,10 +77,10 @@ class NoteFlatTextExp extends Expression { if (foundTokens.length > 0) { const remainingTokens = tokens.filter(token => !foundTokens.includes(token)); - searchDownThePath(parentNote, remainingTokens, path.concat([note.noteId])); + searchDownThePath(parentNote, remainingTokens, [...path, note.noteId]); } else { - searchDownThePath(parentNote, tokens, path.concat([note.noteId])); + searchDownThePath(parentNote, tokens, [...path, note.noteId]); } } }