fix(search): quote underscored terms in FTS5 query sanitization - #16915
Merged
Conversation
FTS5 default tokenizer splits 'sp_new1' into tokens 'sp' and 'new1'.
Without quoting, a search for 'sp_new' becomes an AND query
('sp AND new') that fails to match rows indexed as 'sp_new1'.
Fix: add underscore to the character class in Step 5 regex
([.-] -> [._-]) so underscored terms are wrapped in double quotes.
Also adds test_sanitize_fts5_quotes_underscored_terms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvages #16827 from @crayfish-ai onto current main.
Summary
FTS5 search now returns results for underscored terms like
sp_new, which previously got tokenized assp AND newand produced zero hits even when content matched.Changes
hermes_state.py: Step 5 regex[.-]→[._-]in_sanitize_fts5_query(one-pass, avoids double-quoting).tests/test_hermes_state.py: 8 new cases covering simple/multi/mixed underscores, already-quoted passthrough, and hyphen+dot regression.scripts/release.py: AUTHOR_MAP entry for @crayfish-ai.Validation
search_messages('sp_new')against messages containingsp_new1→ 0 results.scripts/run_tests.sh tests/test_hermes_state.py -k sanitize_fts5→ 5/5 passing.Closes #16827. Credit to @crayfish-ai.