Repository navigation
Fix nested MatchTextAny falling back to substring matching - #8939
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughReplaces the const-generic full-text payload matcher with a single API driven by a new PayloadMatchQueryType (Text, Phrase, TextAny). FieldIndex::special_check_condition now routes Match::Text, Match::Phrase, and Match::TextAny to FullTextIndex::check_payload_match using the appropriate query type. Adds unit and integration tests validating tokenized TextAny behavior, including nested-condition coverage. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/segment/src/index/field_index/full_text_index/text_index.rs (1)
412-415: ⚡ Quick winReplace
_ => falsewith explicit exhaustive match arms.
parse_text_any_queryalways producesParsedQuery::AnyTokens, so the_ => falsearm is unreachable today, but it silently swallows any futureParsedQueryvariants instead of triggering a compile error.As per coding guidelines, prefer explicit exhaustive matches over catch-all
_in production (non-test) code.♻️ Proposed fix
- Ok(match &query { - ParsedQuery::AnyTokens(q) => tokenset.has_any(q), - _ => false, - }) + Ok(match &query { + ParsedQuery::AnyTokens(q) => tokenset.has_any(q), + ParsedQuery::AllTokens(_) | ParsedQuery::Phrase(_) => false, + })As per coding guidelines: "Prefer explicit exhaustive matches over catch-all
_arm in Rust match expressions, so we don't miss handling new enum variants when they are added later (exceptions: tests and benchmarks, or when sure new variants won't affect logic)."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/segment/src/index/field_index/full_text_index/text_index.rs` around lines 412 - 415, Replace the catch-all arm in the match on &query inside the text index lookup with explicit arms for every ParsedQuery variant so the compiler enforces exhaustiveness; specifically, in the match that now has ParsedQuery::AnyTokens(q) => tokenset.has_any(q), replace `_ => false` with explicit matches for the other ParsedQuery variants (e.g., ParsedQuery::AllTokens(_), ParsedQuery::Phrase(_), ParsedQuery::None, etc. — whatever variants exist in the ParsedQuery enum) each returning false (or an appropriate value) so new enum variants will trigger compile errors until handled; locate this change in text_index.rs where the match over ParsedQuery occurs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/segment/src/index/field_index/full_text_index/text_index.rs`:
- Around line 412-415: Replace the catch-all arm in the match on &query inside
the text index lookup with explicit arms for every ParsedQuery variant so the
compiler enforces exhaustiveness; specifically, in the match that now has
ParsedQuery::AnyTokens(q) => tokenset.has_any(q), replace `_ => false` with
explicit matches for the other ParsedQuery variants (e.g.,
ParsedQuery::AllTokens(_), ParsedQuery::Phrase(_), ParsedQuery::None, etc. —
whatever variants exist in the ParsedQuery enum) each returning false (or an
appropriate value) so new enum variants will trigger compile errors until
handled; locate this change in text_index.rs where the match over ParsedQuery
occurs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5ed7e26a-1b00-4914-bc09-5b246f71052a
📒 Files selected for processing (3)
lib/segment/src/index/field_index/field_index_base.rslib/segment/src/index/field_index/full_text_index/tests/mod.rslib/segment/src/index/field_index/full_text_index/text_index.rs
cfd377a to
c22a5d4
Compare
c22a5d4 to
fb230cb
Compare
`special_check_condition` in `FieldIndex` did not handle `Match::TextAny`, so nested-condition evaluation fell through to the `ValueChecker` fallback which uses naive `String::contains` instead of proper full-text tokenization. This caused "good" to match "goodness" inside nested filters. Add `check_payload_match_any` to `FullTextIndex` and wire it into `special_check_condition`. Also replace the catch-all `_ => None` with explicit match arms for all `Match` variants. Co-authored-by: Cursor <[email protected]>
fb230cb to
f91a8fc
Compare
…8939) `special_check_condition` in `FieldIndex` did not handle `Match::TextAny`, so nested-condition evaluation fell through to the `ValueChecker` fallback which uses naive `String::contains` instead of proper full-text tokenization. This caused "good" to match "goodness" inside nested filters. Add `check_payload_match_any` to `FullTextIndex` and wire it into `special_check_condition`. Also replace the catch-all `_ => None` with explicit match arms for all `Match` variants. Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Cursor <[email protected]>
Summary
Fixes #8936.
special_check_conditioninFieldIndex::FullTextIndexdid not have a match arm forMatch::TextAny, causing nestedMatchTextAnyconditions to fall through to theValueCheckerfallback which uses naiveString::contains(substring matching) instead of proper full-text tokenization. This made"good"incorrectly match"goodness"inside nested filters.check_payload_match_anymethod toFullTextIndexthat tokenizes both the query and the payload value through the full-text index's tokenizer before matching.Match::TextAnyintospecial_check_conditionso nested conditions correctly use the full-text index._ => Nonewith explicit match arms over allMatchvariants (Value,Any,Except) to prevent similar omissions in the future.Test plan
test_special_check_condition_match_text_any(in full_text_index tests) verifyingspecial_check_conditionreturnsSome(false)/Some(true)forMatchTextAnytest_nested_match_text_any_uses_full_text_index(in query_checker tests) that exercises the full nested filter path:check_payload→select_nested_indexes→check_field_condition→special_check_conditionwith a realFullTextIndexand nested payloads matching the issue's reproduction scenariocargo check -p segmentcompiles cleanlycargo +nightly fmt --all -- --checkpasses