From 96eff4c410899e36d126475e6748f413640eb5de Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 15 Dec 2020 15:09:00 +0100 Subject: [PATCH] fixed search tests --- spec/search/search.spec.js | 4 ++-- spec/search/value_extractor.spec.js | 4 ++-- src/services/note_cache/entities/note.js | 10 ++++++++++ .../search/expressions/note_cache_flat_text.js | 4 +++- src/services/search/services/parse.js | 6 +++--- src/services/search/services/search.js | 12 +----------- src/services/search/value_extractor.js | 8 ++++++-- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js index 1320027fc..7aa9806f8 100644 --- a/spec/search/search.spec.js +++ b/spec/search/search.spec.js @@ -12,7 +12,7 @@ describe("Search", () => { beforeEach(() => { noteCache.reset(); - rootNote = new NoteBuilder(new Note(noteCache, {noteId: 'root', title: 'root'})); + rootNote = new NoteBuilder(new Note(noteCache, {noteId: 'root', title: 'root', type: 'text'})); new Branch(noteCache, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10}); }); @@ -472,7 +472,7 @@ describe("Search", () => { expect(searchResults.length).toEqual(expectedResultCount); } - test("type", "text", 6); + test("type", "text", 7); test("type", "code", 0); test("mime", "text/html", 6); diff --git a/spec/search/value_extractor.spec.js b/spec/search/value_extractor.spec.js index 12fd07ffa..d82b50ce4 100644 --- a/spec/search/value_extractor.spec.js +++ b/spec/search/value_extractor.spec.js @@ -24,12 +24,12 @@ describe("Value extractor", () => { let valueExtractor = new ValueExtractor(["note", "labels", "capital"]); expect(valueExtractor.validate()).toBeFalsy(); - expect(valueExtractor.extract(austria)).toEqual("vienna"); + expect(valueExtractor.extract(austria)).toEqual("Vienna"); valueExtractor = new ValueExtractor(["#capital"]); expect(valueExtractor.validate()).toBeFalsy(); - expect(valueExtractor.extract(austria)).toEqual("vienna"); + expect(valueExtractor.extract(austria)).toEqual("Vienna"); }); it("parent/child property extraction", async () => { diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js index d2eeda928..29e06dafe 100644 --- a/src/services/note_cache/entities/note.js +++ b/src/services/note_cache/entities/note.js @@ -133,6 +133,16 @@ class Note { return !!this.attributes.find(attr => attr.type === type && attr.name === name); } + getAttributeCaseInsensitive(type, name, value) { + name = name.toLowerCase(); + value = value ? value.toLowerCase() : null; + + return this.attributes.find( + attr => attr.type === type + && attr.name.toLowerCase() === name + && (!value || attr.value.toLowerCase() === value)); + } + getLabelValue(name) { const label = this.attributes.find(attr => attr.type === 'label' && attr.name === name); diff --git a/src/services/search/expressions/note_cache_flat_text.js b/src/services/search/expressions/note_cache_flat_text.js index ce25836c1..a3d7323f5 100644 --- a/src/services/search/expressions/note_cache_flat_text.js +++ b/src/services/search/expressions/note_cache_flat_text.js @@ -89,7 +89,9 @@ class NoteCacheFlatTextExp extends Expression { } for (const attribute of note.ownedAttributes) { - if (attribute.name.includes(token) || attribute.value.includes(token)) { + if (attribute.name.toLowerCase().includes(token) + || attribute.value.toLowerCase().includes(token)) { + foundAttrTokens.push(token); } } diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index 3873ac22c..fe87a3ff6 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -11,7 +11,7 @@ const RelationWhereExp = require('../expressions/relation_where.js'); const PropertyComparisonExp = require('../expressions/property_comparison.js'); const AttributeExistsExp = require('../expressions/attribute_exists.js'); const LabelComparisonExp = require('../expressions/label_comparison.js'); -const NoteCacheFulltextExp = require('../expressions/note_cache_flat_text.js'); +const NoteCacheFlatTextExp = require('../expressions/note_cache_flat_text.js'); const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext.js'); const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext.js'); const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js'); @@ -30,13 +30,13 @@ function getFulltext(tokens, searchContext) { if (searchContext.includeNoteContent) { return new OrExp([ - new NoteCacheFulltextExp(tokens), + new NoteCacheFlatTextExp(tokens), new NoteContentProtectedFulltextExp('*=*', tokens), new NoteContentUnprotectedFulltextExp('*=*', tokens) ]); } else { - return new NoteCacheFulltextExp(tokens); + return new NoteCacheFlatTextExp(tokens); } } diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index c40fb6d19..f49165d15 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -35,15 +35,7 @@ function findNotesWithExpression(expression, searchContext) { const noteSet = expression.execute(allNoteSet, executionContext); const searchResults = noteSet.notes - .map(note => { - const zzz = executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note) - - if (!zzz) { - console.log("missing path", note); - } - - return zzz; - }) + .map(note => executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(note)) .filter(notePathArray => notePathArray.includes(cls.getHoistedNoteId())) .map(notePathArray => new SearchResult(notePathArray)); @@ -67,8 +59,6 @@ function findNotesWithExpression(expression, searchContext) { return a.notePathArray.length < b.notePathArray.length ? -1 : 1; }); - - } return searchResults; diff --git a/src/services/search/value_extractor.js b/src/services/search/value_extractor.js index 9e3baef33..7c4c168f8 100644 --- a/src/services/search/value_extractor.js +++ b/src/services/search/value_extractor.js @@ -82,13 +82,17 @@ class ValueExtractor { if (cur() === 'labels') { i++; - return cursor.getLabelValue(cur()); + const attr = cursor.getAttributeCaseInsensitive('label', cur()); + + return attr ? attr.value : null; } if (cur() === 'relations') { i++; - cursor = cursor.getRelationTarget(cur()); + const attr = cursor.getAttributeCaseInsensitive('relation', cur()); + + cursor = attr ? attr.targetNote : null; } else if (cur() === 'parents') { cursor = cursor.parents[0];