Skip to content

Fix nested MatchTextAny falling back to substring matching - #8939

Merged
generall merged 1 commit into
devfrom
fix/nested-match-text-any
May 7, 2026
Merged

generall merged 1 commit into
devfrom
fix/nested-match-text-any

Conversation

@qdrant-cloud-bot

@qdrant-cloud-bot qdrant-cloud-bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8936.

  • special_check_condition in FieldIndex::FullTextIndex did not have a match arm for Match::TextAny, causing nested MatchTextAny conditions to fall through to the ValueChecker fallback which uses naive String::contains (substring matching) instead of proper full-text tokenization. This made "good" incorrectly match "goodness" inside nested filters.
  • Added check_payload_match_any method to FullTextIndex that tokenizes both the query and the payload value through the full-text index's tokenizer before matching.
  • Wired Match::TextAny into special_check_condition so nested conditions correctly use the full-text index.
  • Replaced the catch-all _ => None with explicit match arms over all Match variants (Value, Any, Except) to prevent similar omissions in the future.

Test plan

  • Added unit test test_special_check_condition_match_text_any (in full_text_index tests) verifying special_check_condition returns Some(false)/Some(true) for MatchTextAny
  • Added end-to-end test test_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_condition with a real FullTextIndex and nested payloads matching the issue's reproduction scenario
  • Both tests confirmed to fail before the fix and pass after
  • All 64 existing full-text index tests pass
  • All query_checker tests pass
  • cargo check -p segment compiles cleanly
  • cargo +nightly fmt --all -- --check passes

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b9c68d1-997d-43a4-8156-e577070965b4

📥 Commits

Reviewing files that changed from the base of the PR and between fb230cb and f91a8fc.

📒 Files selected for processing (4)
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/field_index/full_text_index/tests/mod.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/payload_storage/query_checker.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/segment/src/index/field_index/full_text_index/tests/mod.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/payload_storage/query_checker.rs

📝 Walkthrough

Walkthrough

Replaces 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)
Check name Status Explanation
Title check ✅ Passed The title 'Fix nested MatchTextAny falling back to substring matching' directly and specifically describes the main change: addressing the bug where nested MatchTextAny incorrectly used substring matching instead of full-text index tokenization.
Description check ✅ Passed The PR description is comprehensive and directly related to the changeset. It explains the root cause, solution, implementation details, and includes a detailed test plan with verification steps.
Linked Issues check ✅ Passed The PR fully addresses issue #8936 by: implementing proper full-text tokenization for nested MatchTextAny (replacing substring matching), wiring MatchTextAny into special_check_condition, and adding comprehensive tests that verify the fix works end-to-end.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing nested MatchTextAny token matching: modifications to field_index_base.rs, text_index.rs, and corresponding test additions. No unrelated refactoring or scope creep detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nested-match-text-any

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/segment/src/index/field_index/full_text_index/text_index.rs (1)

412-415: ⚡ Quick win

Replace _ => false with explicit exhaustive match arms.

parse_text_any_query always produces ParsedQuery::AnyTokens, so the _ => false arm is unreachable today, but it silently swallows any future ParsedQuery variants 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

📥 Commits

Reviewing files that changed from the base of the PR and between 01216ca and b086576.

📒 Files selected for processing (3)
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/field_index/full_text_index/tests/mod.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs

`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]>
@generall
generall merged commit 94db47b into dev May 7, 2026
15 checks passed
@generall
generall deleted the fix/nested-match-text-any branch May 7, 2026 10:42
timvisee pushed a commit that referenced this pull request May 8, 2026
…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]>
@timvisee timvisee mentioned this pull request May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants