From b8eeb0371c429d5ea23c3105419114b12329ed5b Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 20 Dec 2021 21:35:12 +0100 Subject: [PATCH] fixed bug in search where note with inherited attribute is not matched when the owning note is not matched, #2457 --- spec/search/search.spec.js | 15 ++++++++++++++ .../search/expressions/attribute_exists.js | 20 +++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js index 795c4f7f2..35da25150 100644 --- a/spec/search/search.spec.js +++ b/spec/search/search.spec.js @@ -157,6 +157,21 @@ describe("Search", () => { expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy(); }); + it("inherited label comparison", () => { + rootNote + .child(note("Europe") + .label('country', '', true) + .child(note("Austria")) + .child(note("Czech Republic")) + ); + + const searchContext = new SearchContext(); + + const searchResults = searchService.findResultsWithQuery('austria #country', searchContext); + expect(searchResults.length).toEqual(1); + expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy(); + }); + it("numeric label comparison fallback to string comparison", () => { // dates should not be coerced into numbers which would then give wrong numbers diff --git a/src/services/search/expressions/attribute_exists.js b/src/services/search/expressions/attribute_exists.js index b72c2d69b..f28185ebc 100644 --- a/src/services/search/expressions/attribute_exists.js +++ b/src/services/search/expressions/attribute_exists.js @@ -23,20 +23,18 @@ class AttributeExistsExp extends Expression { for (const attr of attrs) { const note = attr.note; - if (inputNoteSet.hasNoteId(note.noteId)) { - if (attr.isInheritable) { - resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); - } - else if (note.isTemplate()) { - resultNoteSet.addAll(note.getTemplatedNotes()); - } - else { - resultNoteSet.add(note); - } + if (attr.isInheritable) { + resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); + } + else if (note.isTemplate()) { + resultNoteSet.addAll(note.getTemplatedNotes()); + } + else { + resultNoteSet.add(note); } } - return resultNoteSet; + return resultNoteSet.intersection(inputNoteSet); } }