fixed search tests

This commit is contained in:
zadam 2020-12-15 15:09:00 +01:00
parent 3a12181a57
commit 96eff4c410
7 changed files with 27 additions and 21 deletions

View File

@ -12,7 +12,7 @@ describe("Search", () => {
beforeEach(() => { beforeEach(() => {
noteCache.reset(); 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}); new Branch(noteCache, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10});
}); });
@ -472,7 +472,7 @@ describe("Search", () => {
expect(searchResults.length).toEqual(expectedResultCount); expect(searchResults.length).toEqual(expectedResultCount);
} }
test("type", "text", 6); test("type", "text", 7);
test("type", "code", 0); test("type", "code", 0);
test("mime", "text/html", 6); test("mime", "text/html", 6);

View File

@ -24,12 +24,12 @@ describe("Value extractor", () => {
let valueExtractor = new ValueExtractor(["note", "labels", "capital"]); let valueExtractor = new ValueExtractor(["note", "labels", "capital"]);
expect(valueExtractor.validate()).toBeFalsy(); expect(valueExtractor.validate()).toBeFalsy();
expect(valueExtractor.extract(austria)).toEqual("vienna"); expect(valueExtractor.extract(austria)).toEqual("Vienna");
valueExtractor = new ValueExtractor(["#capital"]); valueExtractor = new ValueExtractor(["#capital"]);
expect(valueExtractor.validate()).toBeFalsy(); expect(valueExtractor.validate()).toBeFalsy();
expect(valueExtractor.extract(austria)).toEqual("vienna"); expect(valueExtractor.extract(austria)).toEqual("Vienna");
}); });
it("parent/child property extraction", async () => { it("parent/child property extraction", async () => {

View File

@ -133,6 +133,16 @@ class Note {
return !!this.attributes.find(attr => attr.type === type && attr.name === name); 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) { getLabelValue(name) {
const label = this.attributes.find(attr => attr.type === 'label' && attr.name === name); const label = this.attributes.find(attr => attr.type === 'label' && attr.name === name);

View File

@ -89,7 +89,9 @@ class NoteCacheFlatTextExp extends Expression {
} }
for (const attribute of note.ownedAttributes) { 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); foundAttrTokens.push(token);
} }
} }

View File

@ -11,7 +11,7 @@ const RelationWhereExp = require('../expressions/relation_where.js');
const PropertyComparisonExp = require('../expressions/property_comparison.js'); const PropertyComparisonExp = require('../expressions/property_comparison.js');
const AttributeExistsExp = require('../expressions/attribute_exists.js'); const AttributeExistsExp = require('../expressions/attribute_exists.js');
const LabelComparisonExp = require('../expressions/label_comparison.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 NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext.js');
const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext.js'); const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext.js');
const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js'); const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js');
@ -30,13 +30,13 @@ function getFulltext(tokens, searchContext) {
if (searchContext.includeNoteContent) { if (searchContext.includeNoteContent) {
return new OrExp([ return new OrExp([
new NoteCacheFulltextExp(tokens), new NoteCacheFlatTextExp(tokens),
new NoteContentProtectedFulltextExp('*=*', tokens), new NoteContentProtectedFulltextExp('*=*', tokens),
new NoteContentUnprotectedFulltextExp('*=*', tokens) new NoteContentUnprotectedFulltextExp('*=*', tokens)
]); ]);
} }
else { else {
return new NoteCacheFulltextExp(tokens); return new NoteCacheFlatTextExp(tokens);
} }
} }

View File

@ -35,15 +35,7 @@ function findNotesWithExpression(expression, searchContext) {
const noteSet = expression.execute(allNoteSet, executionContext); const noteSet = expression.execute(allNoteSet, executionContext);
const searchResults = noteSet.notes const searchResults = noteSet.notes
.map(note => { .map(note => executionContext.noteIdToNotePath[note.noteId] || noteCacheService.getSomePath(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())) .filter(notePathArray => notePathArray.includes(cls.getHoistedNoteId()))
.map(notePathArray => new SearchResult(notePathArray)); .map(notePathArray => new SearchResult(notePathArray));
@ -67,8 +59,6 @@ function findNotesWithExpression(expression, searchContext) {
return a.notePathArray.length < b.notePathArray.length ? -1 : 1; return a.notePathArray.length < b.notePathArray.length ? -1 : 1;
}); });
} }
return searchResults; return searchResults;

View File

@ -82,13 +82,17 @@ class ValueExtractor {
if (cur() === 'labels') { if (cur() === 'labels') {
i++; i++;
return cursor.getLabelValue(cur()); const attr = cursor.getAttributeCaseInsensitive('label', cur());
return attr ? attr.value : null;
} }
if (cur() === 'relations') { if (cur() === 'relations') {
i++; i++;
cursor = cursor.getRelationTarget(cur()); const attr = cursor.getAttributeCaseInsensitive('relation', cur());
cursor = attr ? attr.targetNote : null;
} }
else if (cur() === 'parents') { else if (cur() === 'parents') {
cursor = cursor.parents[0]; cursor = cursor.parents[0];