mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixed search tests
This commit is contained in:
parent
3a12181a57
commit
96eff4c410
@ -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);
|
||||||
|
@ -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 () => {
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user