Skip to content

Build your personal knowledge base with Trilium Notes

chore(search): drop this branch's lexer fuzzy-operator fix, now on main

Elian Doranf58bcc0b6111
diff --git a/packages/trilium-core/src/services/search/services/lex.spec.ts b/packages/trilium-core/src/services/search/services/lex.spec.ts
index ec2b9b8def..9a941449a9 100644
--- a/packages/trilium-core/src/services/search/services/lex.spec.ts
+++ b/packages/trilium-core/src/services/search/services/lex.spec.ts
@@ -177,6 +177,8 @@ describe("Lexer expression", () => {
expect(lex(`note.title ~* books`).expressionTokens.map((t) => t.token)).toEqual(["note", ".", "title", "~*", "books"]);
expect(lex(`#author ~= tolkien`).expressionTokens.map((t) => t.token)).toEqual(["#author", "~=", "tolkien"]);
expect(lex(`#author ~*'lord of the rings'`).expressionTokens.map((t) => t.token)).toEqual(["#author", "~*", "lord of the rings"]);
+ expect(lex(`#author~=tolkien`).expressionTokens.map((t) => t.token)).toEqual(["#author", "~=", "tolkien"]);
+ expect(lex(`~author.title ~= tolkien`).expressionTokens.map((t) => t.token)).toEqual(["~author", ".", "title", "~=", "tolkien"]);
});
it("relation prefix still works when ~ is not followed by = or *", () => {
@@ -192,29 +194,6 @@ describe("Lexer expression", () => {
});
});
-describe("Lexer fuzzy operators ~= and ~*", () => {
- it("tokenizes ~= as a single operator (with and without surrounding spaces)", () => {
- expect(lex("#title ~= books").expressionTokens.map((t) => t.token)).toEqual(["#title", "~=", "books"]);
- expect(lex("#title~=books").expressionTokens.map((t) => t.token)).toEqual(["#title", "~=", "books"]);
- expect(lex("#book ~= tolkien").expressionTokens.map((t) => t.token)).toEqual(["#book", "~=", "tolkien"]);
- });
-
- it("tokenizes ~* as a single operator", () => {
- expect(lex("#title ~* books").expressionTokens.map((t) => t.token)).toEqual(["#title", "~*", "books"]);
- });
-
- it("supports ~= on note properties and on relation properties", () => {
- expect(lex("note.title ~= books").expressionTokens.map((t) => t.token)).toEqual(["note", ".", "title", "~=", "books"]);
- expect(lex("~author.title ~= tolkien").expressionTokens.map((t) => t.token)).toEqual(["~author", ".", "title", "~=", "tolkien"]);
- });
-
- it("still treats a leading ~ as the start of a relation (regression)", () => {
- // The first "~" of the query starts a relation and ends fulltext, so
- // "~author.title = x" must remain a relation comparison, not a fuzzy op.
- expect(lex("~author.title = x").expressionTokens.map((t) => t.token)).toEqual(["~author", ".", "title", "=", "x"]);
- });
-});
-
describe("Lexer invalid queries and edge cases", () => {
it("concatenated attributes", () => {
expect(lex("#label~relation").expressionTokens.map((t) => t.token)).toEqual(["#label", "~relation"]);
diff --git a/packages/trilium-core/src/services/search/services/lex.ts b/packages/trilium-core/src/services/search/services/lex.ts
index 2c73fe0602..6d41146d25 100644
--- a/packages/trilium-core/src/services/search/services/lex.ts
+++ b/packages/trilium-core/src/services/search/services/lex.ts
@@ -93,18 +93,6 @@ function lex(str: string) {
fulltextEnded = true;
}
- // Fuzzy operators ~= and ~*. The `fulltextEnded` guard keeps the first
- // `~` of a query starting a relation (e.g. `~author.title=x`); only a
- // `~` that appears once we're in the expression section and is followed
- // by `=`/`*` is treated as a two-character fuzzy operator.
- if (chr === "~" && fulltextEnded && (str[i + 1] === "=" || str[i + 1] === "*")) {
- finishWord(i - 1);
- currentWord = "~" + str[i + 1];
- finishWord(i + 1);
- i++;
- continue;
- }
-
if (chr === "#" || chr === "~") {
if (!fulltextEnded) {
fulltextEnded = true;