From 3a12181a57e919f05fab573838c19f81604cea87 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 14 Dec 2020 23:59:05 +0100 Subject: [PATCH] search fixes WIP --- spec/search/note_cache_mocking.js | 3 ++- spec/search/search.spec.js | 2 +- spec/search/value_extractor.spec.js | 4 ++-- src/entities/note_revision.js | 1 - src/services/cls.js | 2 +- src/services/search/expressions/label_comparison.js | 5 +++-- src/services/search/services/search.js | 10 +++++++++- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/spec/search/note_cache_mocking.js b/spec/search/note_cache_mocking.js index 0554093a9..2912fe0c2 100644 --- a/spec/search/note_cache_mocking.js +++ b/spec/search/note_cache_mocking.js @@ -46,7 +46,8 @@ class NoteBuilder { branchId: id(), noteId: childNoteBuilder.note.noteId, parentNoteId: this.note.noteId, - prefix + prefix, + notePosition: 10 }); return this; diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js index 861b902d8..1320027fc 100644 --- a/spec/search/search.spec.js +++ b/spec/search/search.spec.js @@ -13,7 +13,7 @@ describe("Search", () => { noteCache.reset(); rootNote = new NoteBuilder(new Note(noteCache, {noteId: 'root', title: 'root'})); - new Branch(noteCache, {branchId: 'root', noteId: 'root', parentNoteId: 'none'}); + new Branch(noteCache, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10}); }); it("simple path match", () => { diff --git a/spec/search/value_extractor.spec.js b/spec/search/value_extractor.spec.js index 07b3cafd5..12fd07ffa 100644 --- a/spec/search/value_extractor.spec.js +++ b/spec/search/value_extractor.spec.js @@ -59,12 +59,12 @@ describe("Value extractor", () => { let valueExtractor = new ValueExtractor(["note", "relations", "neighbor", "labels", "capital"]); expect(valueExtractor.validate()).toBeFalsy(); - expect(valueExtractor.extract(austria.note)).toEqual("prague"); + expect(valueExtractor.extract(austria.note)).toEqual("Prague"); valueExtractor = new ValueExtractor(["~neighbor", "labels", "capital"]); expect(valueExtractor.validate()).toBeFalsy(); - expect(valueExtractor.extract(austria.note)).toEqual("prague"); + expect(valueExtractor.extract(austria.note)).toEqual("Prague"); }); }); diff --git a/src/entities/note_revision.js b/src/entities/note_revision.js index a51f27e25..eee980182 100644 --- a/src/entities/note_revision.js +++ b/src/entities/note_revision.js @@ -79,7 +79,6 @@ class NoteRevision extends Entity { } this.content = res.content; - if (this.isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { this.content = protectedSessionService.decrypt(this.content); diff --git a/src/services/cls.js b/src/services/cls.js index b675e2175..a7b10e802 100644 --- a/src/services/cls.js +++ b/src/services/cls.js @@ -25,7 +25,7 @@ function set(key, value) { } function getHoistedNoteId() { - return namespace.get('hoistedNoteId'); + return namespace.get('hoistedNoteId') || 'root'; } function getSourceId() { diff --git a/src/services/search/expressions/label_comparison.js b/src/services/search/expressions/label_comparison.js index 143c41b6e..817fe5c28 100644 --- a/src/services/search/expressions/label_comparison.js +++ b/src/services/search/expressions/label_comparison.js @@ -9,7 +9,7 @@ class LabelComparisonExp extends Expression { super(); this.attributeType = attributeType; - this.attributeName = attributeName; + this.attributeName = attributeName.toLowerCase(); this.comparator = comparator; } @@ -19,8 +19,9 @@ class LabelComparisonExp extends Expression { for (const attr of attrs) { const note = attr.note; + const value = attr.value ? attr.value.toLowerCase() : attr.value; - if (inputNoteSet.hasNoteId(note.noteId) && this.comparator(attr.value)) { + if (inputNoteSet.hasNoteId(note.noteId) && this.comparator(value)) { if (attr.isInheritable) { resultNoteSet.addAll(note.subtreeNotesIncludingTemplated); } diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index 224e55c18..c40fb6d19 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -35,7 +35,15 @@ function findNotesWithExpression(expression, searchContext) { const noteSet = expression.execute(allNoteSet, executionContext); const searchResults = noteSet.notes - .map(note => executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note)) + .map(note => { + const zzz = executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note) + + if (!zzz) { + console.log("missing path", note); + } + + return zzz; + }) .filter(notePathArray => notePathArray.includes(cls.getHoistedNoteId())) .map(notePathArray => new SearchResult(notePathArray));