Repository navigation
fix(fulltext2): keep the whole CJK stem for a BOOLEAN trailing * (#29274) - #29346
Conversation
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? |
…rixorigin#29274) A boolean-mode CJK operand with a trailing `*` kept only the FIRST token and prefix-matched it, dropping the rest of the stem and over-matching: - ngram / default / "" tile 苹果香蕉 into 苹果香/果香蕉/香蕉/蕉 and kept only 苹果香, so `苹果香蕉*` returned 苹果香瓜 (shares 苹果香, diverges at rune 4). - gojieba segments it into words 苹果/香蕉 and kept only 苹果, so `苹果香蕉*` returned every 苹果* document (1,2,3,4). rawToClauseParser's rc.star branch returned clausePrefix over terms[:1]. When the operand tokenizes into more than one token, decompose it the same way the unstarred/quoted operand does, via phraseSlots: the positional phrase pins the whole stem (ngram: 苹果香@0+果香蕉@3; gojieba: 苹果@0+香蕉@…), and a phrase already allows trailing document content -- exactly the `*` semantics -- so `苹果香蕉*` matches 苹果香蕉 / 苹果香蕉西瓜 but not 苹果香瓜. A SINGLE-token stem keeps its genuine prefix: gojieba `苹果*` stays a word prefix (still matches 红苹果甜's 苹果甜); for ngram the gate is always taken and phraseSlots itself emits a presence-only prefix slot for a run shorter than a trigram (slotPostings expands it via prefixTerms), so a short ngram stem such as `苹果*` also keeps prefix behavior. Non-CJK (Latin) stays a plain first-token prefix. Also fixes StreamQuery (shares buildBooleanQuery). The four operand branches (bare-CJK, quoted, starred-CJK, default) built the same "phraseSlots -> err -> empty -> clausePhrase" block; factor it into phraseClause to remove the duplication and its repeated guards. Verified live for ngram AND gojieba: `苹果香蕉*` / `+苹果香蕉*` -> {1,3}, `苹果香*` -> {1,2,3}, `苹果*` -> {1,2,3,4}, NL 苹果香蕉 -> {1,3}. Tests: TestBooleanCJKTrailingStarKeepsWholeStem ("" / default / ngram) and TestBooleanGojiebaTrailingStarKeepsWholeStem, both proven to fail on the pre-fix code; TestRawToClauseParserEdgeCases / TestPhraseClause cover the operand classification and empty/edge inputs directly (rawToClauseParser 72.7% -> 91.4%). BVT fulltext2_cjk_boolean_prefix (ngram + gojieba) locks the SQL behavior. Full pkg/fulltext2 UT (87.5%) and the fulltext2 BVT suite (930) pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…cheap (matrixorigin#29274) Two regressions from the starred-stem phrase decomposition: 1. gojieba final word: `苹果香*` segments to 苹果@0 + 香@6, but a document 苹果香蕉 stored 苹果@0 + 香蕉@6. Leaving the last slot exact dropped the row. The final gojieba word is a PARTIAL the * cut, so prefix-match it even when CJK (the head words stay positionally exact, so a divergent head is still excluded). 2. single-slot ngram: a complete-trigram stem `苹果香*` (or a sub-trigram run 中*) decomposes to ONE slot. Converting it to a one-slot positional phrase forced matchPhrase to decode every position of a hot prefix (measured ~14x time, ~20x allocs). There is no second slot to over-match, so keep the cheap prefix evaluation (doc-id/tf) as before. Multi-slot ngram stems keep the positional phrase (the original over-match fix) and a Latin tail still prefix-matches (the earlier mixed CJK/Latin fix). Adds gojieba partial-CJK-word and single-slot-stays-prefix regressions (unit + BVT). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 7ce85dbb07f43dbe78ec7117277fc23161cb76c1 against merge-base 426cf10b000b6a828e8c69f1af26082f26036ed3. All four changed files reviewed. The two blockers from my previous review are resolved; no new blocking findings.
- gojieba now prefix-matches its final Chinese word while retaining preceding positional constraints. The original whole-stem and mixed CJK/Latin cases remain correct.
- Single-slot ngram stems return to the position-free prefix evaluator. On the previous loaded-index benchmark (6,000 documents, 2,000 hits, 250 occurrences/hit, BM25 top 10), current runs are 0.119–0.134 ms/query and ~200,032 B / 93 allocations, versus 0.120–0.122 ms and the same allocations for the prior-prefix control. Row/score sets match; the former ~1.9ms / 4.32MB regression is gone.
Verification:
- Full
pkg/fulltext2with-vet=all -count=1: PASS, 526 test/subtest pass events, no skips; gojieba executed. - Reviewer-only loaded-index probes: SearchQuery and StreamQuery both pass repeated partial-CJK/mixed-Latin cases, divergent-head/tail and wrong-position controls, absent prefixes, MUST-NOT interaction, and consumer-error followed by successful reuse.
- Exact changed mo-tester case ran twice in normal comparison mode on the same fresh single-CN instance: 32/32 each (0.406s / 0.227s). Database and relation residue counts were zero after each run, checked before subsequent runner cleanup. Test-owned server exited cleanly.
- Exact-head CI run 36149032476 is green; its pessimistic artifact independently confirms this case ran 32/32.
The small shared phrase helper and narrow parser-specific tail rule are proportionate; no additional framework is warranted. No production code was changed during review.
Merge Queue Status
This pull request spent 37 seconds in the queue, with no time running CI. ReasonPull request #29346 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #29274
What this PR does / why we need it:
A fulltext2 boolean-mode CJK operand with a trailing
*kept only the first token and prefix-matched it, dropping the rest of the stem and over-matching. Same class of bug in two tokenizers:苹果香蕉into overlapping trigrams苹果香/果香蕉/香蕉/蕉and kept only苹果香, so苹果香蕉*returned苹果香瓜(shares苹果香, diverges at rune 4).苹果/香蕉and kept only苹果, so苹果香蕉*returned every苹果*document (1,2,3,4).Root cause:
rawToClauseParser'src.starbranch returnedclausePrefixoverterms[:1].Fix: when the operand tokenizes into more than one token, decompose it the same way the unstarred/quoted operand already does, via
phraseSlots. The positional phrase pins the whole stem (ngram:苹果香@0 + 果香蕉@3; gojieba:苹果@0 + 香蕉@…), and a phrase already allows trailing document content — exactly the*semantics — so苹果香蕉*matches苹果香蕉/苹果香蕉西瓜but not苹果香瓜.A single-token stem keeps its genuine prefix: gojieba
苹果*stays a word prefix (still matches红苹果甜's苹果甜); for ngram the gate is always taken andphraseSlotsitself emits a presence-only prefix slot for a run shorter than a trigram (slotPostingsexpands it viaprefixTerms), so a short ngram stem such as苹果*also keeps prefix behavior. Non-CJK (Latin) stays a plain first-token prefix. This also fixesStreamQuery, which sharesbuildBooleanQuery.Verification
Live (ngram and gojieba):
苹果香蕉*/+苹果香蕉*→ {1,3},苹果香*→ {1,2,3},苹果*→ {1,2,3,4}, NL苹果香蕉→ {1,3}.""/default/ngramand gojieba, proven to fail on the pre-fix code.fulltext2_cjk_boolean_prefix(ngram + gojieba sections) locks the SQL behavior.pkg/fulltext2UT and thefulltext2BVT suite (930) pass; gofmt clean.