Skip to content

Build your personal knowledge base with Trilium Notes

fixed search tests

zadam96eff4c41089
diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js
index 1320027fc6..7aa9806f8d 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 12fd07ffaa..d82b50ce45 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 d2eeda928f..29e06dafe2 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 ce25836c19..a3d7323f55 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 3873ac22c9..fe87a3ff69 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 c40fb6d19b..f49165d150 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 9e3baef331..7c4c168f86 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];