Skip to content

fix(search): tokenize ~= and ~* as single fuzzy-match operators#9508

Open
mrbeandev wants to merge 1 commit intoTriliumNext:mainfrom
mrbeandev:fix-fuzzy-search-operator-tokenization
Open

fix(search): tokenize ~= and ~* as single fuzzy-match operators#9508
mrbeandev wants to merge 1 commit intoTriliumNext:mainfrom
mrbeandev:fix-fuzzy-search-operator-tokenization

Conversation

@mrbeandev
Copy link
Copy Markdown

Summary

  • The search lexer emitted ~ and =/* as two separate tokens whenever a query used the fuzzy-match operators ~= or ~*, so queries such as note.title ~= books failed with Unrecognized expression books even though the parser already knows about those operators (parse.ts OPERATORS set).
  • This PR adds a single branch to lex.ts that keeps ~= / ~* glued together when the current word is the bare ~, following the same pattern used one branch above for ~! and #!.
  • Relation prefixes like ~author keep working because their first character is never = or *.

Fixes #9426

Test plan

  • pnpm exec vitest run src/services/search/services/lex.spec.ts — 27/27 pass, including four new regression cases for note.title ~= books, note.title ~* books, #author ~= tolkien, #author ~*'lord of the rings', and a ~author.title = Tolkien guard for the relation-prefix path.
  • pnpm exec vitest run src/services/search — full search suite 144 passed / 26 skipped, no regressions.

The lexer treats `~` as a relation prefix (as in `~author.title`), so
when a user wrote `note.title ~= books` or `note.title ~* books` the
`~` was emitted as its own token and the `=`/`*` started a second
token. The parser then failed with "Unrecognized expression books".

Add a dedicated branch that keeps `~=` and `~*` glued together when the
current word is the bare tilde, mirroring how `~!` and `#!` are handled
one branch above. Relation prefixes such as `~author` are unaffected
because they never have `=` or `*` as their first character.

Regression coverage is added in lex.spec.ts for both operators, the
quoted variant, and a relation-prefix case to guard against accidental
tokenization of `~foo` as an operator in the future.

Fixes TriliumNext#9426
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 20, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the lexer to correctly tokenize fuzzy-match operators ~= and ~* as single units, preventing them from being misinterpreted as a relation prefix followed by an operator. Corresponding regression tests have been added to verify this behavior and ensure that the standard relation prefix ~ remains functional. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fuzzy search not working

1 participant