fix(search): quote underscored terms in FTS5 query sanitization - #16827
Closed
crayfish-ai wants to merge 1 commit into
Closed
fix(search): quote underscored terms in FTS5 query sanitization#16827crayfish-ai wants to merge 1 commit into
crayfish-ai wants to merge 1 commit into
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.
Collaborator
Contributor
|
Salvaged via #16915 — your commit was cherry-picked onto current main with your authorship preserved. Thanks for the fix! |
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.
Summary
Fix FTS5 query sanitization to properly quote underscored terms.
Problem
_sanitize_fts5_queryStep 5 regex[.-]was missing underscore, so underscored terms likesp_newwere NOT quoted and FTS5 split them into AND tokens (sp AND new), causing searches to return 0 results even when matching content exists.Fix
Change Step 5 regex from
[.-]to[._-]so underscored terms are properly quoted as"sp_new"and matched as prefix search.Files: 2 changed, +26/-2 lines