Skip to content

Build your personal knowledge base with Trilium Notes

feat(search): clarify error message for use of unquoted note

Elian Doran1b8c234f3084
diff --git a/apps/server/src/services/search/services/parse.spec.ts b/apps/server/src/services/search/services/parse.spec.ts
index cd59ce7f09..ccf4925499 100644
--- a/apps/server/src/services/search/services/parse.spec.ts
+++ b/apps/server/src/services/search/services/parse.spec.ts
@@ -285,7 +285,7 @@ describe("Invalid expressions", () => {
searchContext
});
- expect(searchContext.error).toEqual(`Error near token "#second" in "#first = #second", it's possible to compare with constant only.`);
+ expect(searchContext.error).toEqual(`Error in "#first = #second": cannot compare with "#second". To search for a literal value, use quotes: "#second"`);
searchContext = new SearchContext();
searchContext.originalQuery = "#first = note.relations.second";
@@ -296,7 +296,7 @@ describe("Invalid expressions", () => {
searchContext
});
- expect(searchContext.error).toEqual(`Error near token "note" in "#first = note.relations.second", it's possible to compare with constant only.`);
+ expect(searchContext.error).toEqual(`Error in "#first = note.relations.second": "note" is a reserved keyword. To search for a literal value, use quotes: "note"`);
const rootExp = parse(
{
@@ -317,6 +317,27 @@ describe("Invalid expressions", () => {
expect(labelComparisonExp.attributeType).toEqual("label");
expect(labelComparisonExp.attributeName).toEqual("first");
expect(labelComparisonExp.comparator).toBeTruthy();
+
+ // Verify that quoted "note" keyword works (issue #8850)
+ const rootExp2 = parse(
+ {
+ fulltextTokens: [],
+ expressionTokens: [
+ { token: "#clipType", inQuotes: false },
+ { token: "=", inQuotes: false },
+ { token: "note", inQuotes: true }
+ ],
+ searchContext: new SearchContext()
+ },
+ AndExp
+ );
+
+ assertIsArchived(rootExp2.subExpressions[0]);
+
+ const labelComparisonExp2 = expectExpression(rootExp2.subExpressions[2], LabelComparisonExp);
+ expect(labelComparisonExp2.attributeType).toEqual("label");
+ expect(labelComparisonExp2.attributeName).toEqual("cliptype");
+ expect(labelComparisonExp2.comparator).toBeTruthy();
});
it("searching by relation without note property", () => {
diff --git a/apps/server/src/services/search/services/parse.ts b/apps/server/src/services/search/services/parse.ts
index a117bf9928..504eeb4bea 100644
--- a/apps/server/src/services/search/services/parse.ts
+++ b/apps/server/src/services/search/services/parse.ts
@@ -98,7 +98,10 @@ function getExpression(tokens: TokenData[], searchContext: SearchContext, level
const operand = tokens[i];
if (!operand.inQuotes && (operand.token.startsWith("#") || operand.token.startsWith("~") || operand.token === "note")) {
- searchContext.addError(`Error near token "${operand.token}" in ${context(i)}, it's possible to compare with constant only.`);
+ const hint = operand.token === "note"
+ ? `"${operand.token}" is a reserved keyword. To search for a literal value, use quotes: "${operand.token}"`
+ : `cannot compare with "${operand.token}". To search for a literal value, use quotes: "${operand.token}"`;
+ searchContext.addError(`Error in ${context(i)}: ${hint}`);
return null;
}