Repository navigation
fix(fulltext): lowercase a <3-rune NL pattern before the prefix search (#29296) - #29354
Conversation
matrixorigin#29296) A classic-fulltext natural-language / default pattern shorter than 3 runes was turned into a STAR prefix of the RAW pattern by ParsePatternInNLMode, with no case folding. Indexed Latin tokens are stored lowercased (SimpleTokenizer.outputLatin) and prefix_eq is case-sensitive, so `AGAINST('Hi')` / `'HI'` / `'Ab')` prefix-searched the capitalized string and returned no rows even though the documents contain `high` / `hi` / `Abyss`. Boolean mode already lowercases its whole pattern, and a >=3-rune NL pattern folds case through the tokenizer -- only this short branch missed it. Lowercase the pattern before appending the `*`. The other short-pattern STAR sites in the same function build from tokenizer output (already lowercased), so this is the only site. The <3-rune prefix rule and the >=3-rune exact-token rule are unchanged, and the `-5` breaker-prefix case is out of scope. fulltext2 already lowercases its own query path. Verified live: `Hi`/`HI` -> {1,2}, `Ab`/`AB` -> {5} (all were empty), lowercase controls and `hig` (3-rune exact, no match) / `HIGH` (>=3 tokenized) unchanged. Test TestParsePatternInNLModeShortLowercases over "" / ngram / default, proven to fail on the pre-fix code; BVT fulltext_short_pattern_case locks the SQL behavior. Full pkg/fulltext UT and the classic fulltext (1636) and fulltext2 (909) BVT suites pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
fixed |
# Conflicts: # pkg/fulltext/jieba_test.go
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review at exact head c788ea94700fb7202981caa549c2db83cfcbf29b: APPROVE. The original short-pattern defect and the follow-up counterexamples are addressed: normalization matches SimpleTokenizer’s Latin-only folding for the relevant parsers and preserves non-Latin runes and json_value case, instead of applying blanket strings.ToLower. That keeps index/query token semantics aligned while retaining the existing <3-rune prefix rule and >=3-rune exact-token path. The real-SQL regression and parser tests cover the previously failing case plus case-preserving controls; required exact-head UT, SCA, coverage, PROXY and pessimistic BVT pass. I found no need for extra state or design machinery and no confirmed new unhappy-path or performance regression.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
…efix search (#30484) (#30612) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #30484 ## What this PR does / why we need it: Backport of #29296 / PR #29354 (`d99187d7b3`) to **4.2-dev**. On the 4.2 line, a classic `FULLTEXT` natural-language query term **shorter than 3 runes that contains uppercase** silently matched nothing — `DB`, `Db`, `Xy`, `XY` → empty, while `db`/`xy` and any length-≥3 term (`ABC`, `MatrixOne`) work. This hits the very common 2-letter uppercase acronyms (`AI`, `DB`, `ID`, `UI`, `IP`, `VM`, …) as a silent under-recall. ### Root cause `ParsePatternInNLMode` handles a term shorter than `ngram_size` (3) with a prefix (`STAR`) shortcut that built the pattern from the **raw** query string, bypassing the case-folding the `SimpleTokenizer` applies to longer terms (and that the document side applies at index time). So `DB` became the prefix `DB*` and looked up the lowercased stored token `db`, matching nothing. (Boolean mode was unaffected — it lowercases the whole pattern up front.) ### Fix (cherry-picked from main) Normalize the short pattern the **same way the index stores tokens**: `normalizeShortPattern` folds only Latin-class runes (`<0x7FF`, matching `outputLatin`) and preserves wider runes verbatim (`outputCJK`). A blanket `strings.ToLower` would be wrong — it would fold full-width/CJK capitals like `A`/`ẞ` that the ngram index stores cased; `json_value` is preserved verbatim. Cherry-pick is clean in `pkg/fulltext/fulltext.go`; the only conflict was an adjacent test block in `jieba_test.go` (other backlog tests not part of this fix), resolved to keep exactly #29296's three regression tests. ### Validation (on 4.2-dev) - `pkg/fulltext` unit tests pass, including the three ported #29296 regressions (`TestParsePatternInNLModeShortLowercases`, `...ShortMatchesTokenizerFolding`, `...ShortJSONValuePreservesCase`). - End-to-end on a built 4.2-dev `mo-service`: `DB`/`Db`/`Xy`/`XY` now return the expected rows, while `db`/`ABC` remain correct. - BVT `fulltext/fulltext_short_pattern_case` passes 25/25 (`-g -n`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #29296
What this PR does / why we need it:
A classic-fulltext natural-language / default
MATCH ... AGAINSTpattern shorter than 3 runes was turned into aSTARprefix of the raw pattern byParsePatternInNLMode, with no case folding. Indexed Latin tokens are stored lowercased (SimpleTokenizer.outputLatin) andprefix_eqis case-sensitive, soAGAINST('Hi')/'HI'/'Ab')prefix-searched the capitalized string and returned 0 rows even though the documents containhigh/hi/Abyss.Boolean mode already lowercases its whole pattern, and a ≥3-rune NL pattern folds case through the tokenizer — only this short branch missed it.
Fix: lowercase the pattern before appending
*:The other short-pattern
STARsites in the same function build from tokenizer output (already lowercased), so this is the only site. The<3-rune prefix rule and the ≥3-rune exact-token rule are unchanged, and the-5breaker-prefix case is out of scope. fulltext2 already lowercases its own query path.Verification
Live:
Hi/HI→{1,2},Ab/AB→{5}(all were empty); lowercase controls,hig(3-rune exact → no match), andHIGH(≥3 tokenized →{1}) unchanged.TestParsePatternInNLModeShortLowercasesover""/ngram/default(plus thehigexact-token control), proven to fail on the pre-fix code.fulltext_short_pattern_caselocks the SQL behavior.pkg/fulltextUT and the classicfulltext(1636) andfulltext2(909) BVT suites pass; gofmt clean.