Skip to content

fix(search): FTS5 special-char queries (hyphens, dots, paths) now match via phrase-prefix#27

Open
chokmah-me wants to merge 1 commit into
dezgit2025:mainfrom
chokmah-me:fix/fts5-special-char-queries
Open

fix(search): FTS5 special-char queries (hyphens, dots, paths) now match via phrase-prefix#27
chokmah-me wants to merge 1 commit into
dezgit2025:mainfrom
chokmah-me:fix/fts5-special-char-queries

Conversation

@chokmah-me

Copy link
Copy Markdown

Provenance

This fix was found and authored by Claude (Fable 5, Anthropic) while running a "Bitter Lesson" review over a real user's Claude Code harness — auditing which parts of the setup were prompt-space workarounds for tool bugs. The user's global instructions carried this warning:

Avoid hyphens/dots in single-token searches — FTS5 splits on them (prefer search "session recall" over search "session-recall").

That's a documentation patch for a fixable tool behavior, so we fixed the tool instead and deleted the warning. The user (@chokmah-me) reviewed and greenlit submitting the fix upstream.

Problem

sanitize_fts5_query quotes any token containing FTS5 special characters wholesale, without a prefix star:

  • session-recall"session-recall" — an exact adjacent-phrase query with no prefix matching
  • CLAUDE.md"CLAUDE.md", src/main.py"src/main.py" — same

In practice these queries usually return nothing, which pushes users into exactly the workaround quoted above.

Fix

Tokens containing special characters are split on those characters into the subtokens unicode61 actually indexes, then searched as a phrase-prefix query:

Query token Before After
session-recall "session-recall" "session recall"*
CLAUDE.md "CLAUDE.md" "CLAUDE md"*
src/main.py "src/main.py" "src main py"*
!!! (all special) "!!!" (syntax risk) dropped; all-special query → None

Plain tokens keep their existing token* behavior.

Verification

  • test_search_sanitize.py updated to pin the new behavior, +2 new tests (all-special query → None, pure-special token dropped): 15/15 pass
  • Full suite: 254 passed, 16 failed on this branch vs 252 passed, 16 failed on main in the same environment — the 16 failures are pre-existing local/Windows issues (symlink-privilege tests, env-dependent e2e fixtures), verified identical before and after the change
  • Live-verified against a real .sr-index.db: search 'session-recall' and search 'CLAUDE.md' went from fragile/empty to returning correct hits

🤖 Generated with Claude Code

Queries containing hyphens, dots, slashes etc. (e.g. 'session-recall',
'CLAUDE.md', 'src/main.py') previously got quoted whole with no prefix
star, so they only matched as exact adjacent phrases and usually
returned nothing. Now such tokens are split on the special characters
into the subtokens unicode61 actually indexes and searched as a
phrase-prefix query: session-recall -> "session recall"*.

Also handles tokens that are all special chars (dropped; all-special
queries return None like empty queries).

Found by Claude (Fable 5) during a Bitter Lesson review of a real
user's harness; the user greenlit submitting the fix upstream.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant