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(() => {
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);

View file

@ -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 () => {

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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];