Skip to content

refactor(field_index): add condition_checker trait method (foundation) - #8978

Merged
generall merged 4 commits into
devfrom
condition-checker-trait
May 11, 2026
Merged

generall merged 4 commits into
devfrom
condition-checker-trait

Conversation

@generall

Copy link
Copy Markdown
Member

Summary

First PR in the condition-checker-migration sub-plan. Foundation only — every typed index keeps the default `None` impl, so the legacy dispatch in `field_condition_index` handles every condition. Behaviour unchanged.

What changed

  1. `PayloadFieldIndexRead::condition_checker` — new method with default `None` body. Lets each typed index advertise the `FieldCondition` shapes it can serve as a per-point checker closure.

  2. `FieldIndexRead::get_payload_field_index_read` — new required method returning `&dyn PayloadFieldIndexRead`. Distinct from the existing inherent `get_payload_field_index` (which returns `&dyn PayloadFieldIndex`, exposing write-side methods) — the read path now hands back a handle that can't accidentally reach `wipe` / `flusher` / `files`.

  3. Default impls on `FieldIndexRead` — five pure-delegation methods (`count_indexed_points`, `filter`, `estimate_cardinality`, `for_each_payload_block`, `condition_checker`) get default bodies using `get_payload_field_index_read`. `impl FieldIndexRead for FieldIndex` drops the explicit copies — only variant-specific methods remain (`get_telemetry_data`, `values_*`, `special_check_condition`, `as_numeric`, `as_facet_index`) plus the new required `get_payload_field_index_read`.

  4. `field_condition_index` in `read_view/condition_converter/helpers.rs` tries `index.condition_checker(...)` first, falls through to the existing legacy match. As variants migrate in follow-up PRs, the match shrinks; PR 7 of the sub-plan deletes it entirely.

Why `&dyn` rather than `impl PayloadFieldIndexRead + '_`

RPITIT requires the implementation to return a single concrete type. The per-variant arms here produce `&NumericIndexInner`, `&MapIndex`, `&GeoMapIndex`, etc. — different types. A unifying borrowed-enum wrapper (à la `FacetIndexEnum<'a>`) would be more code than the trait-object indirection saves. `as_numeric` / `as_facet_index` get away with `impl Trait` because they each have such a unifying enum already.

Test plan

  • `cargo build --workspace --tests` (clean)
  • `cargo test -p segment` — 666 unit + 120 integration tests pass
  • `cargo +nightly fmt --all -- --check`

🤖 Generated with Claude Code

First PR in the condition-checker-migration sub-plan
(docs/plans/field-index-read-trait/condition-checker-migration/).
Purely additive: every existing typed index keeps the default `None`
impl, so the legacy match in `field_condition_index` handles every
condition. Behaviour unchanged.

Changes:

1. PayloadFieldIndexRead::condition_checker — new method with default
   `None` body. Lets each typed index advertise the conditions it can
   serve.

2. FieldIndexRead::get_payload_field_index_read — new required method
   returning `&dyn PayloadFieldIndexRead`. Distinct from the existing
   inherent `get_payload_field_index` (which returns `&dyn PayloadFieldIndex`,
   exposing write-side methods) — the read path now hands back a
   handle that can't accidentally call wipe / flusher / files.

3. Five pure-delegation methods on FieldIndexRead get default impls
   using the new getter (count_indexed_points, filter,
   estimate_cardinality, for_each_payload_block, condition_checker).
   `impl FieldIndexRead for FieldIndex` drops their explicit bodies.

4. field_condition_index in read_view/condition_converter/helpers.rs
   tries `index.condition_checker(...)` first, then falls through to
   the existing legacy match. The match handles everything until
   per-variant overrides land in the follow-up PRs.

Why `&dyn` rather than `impl PayloadFieldIndexRead + '_`: RPITIT
requires a single concrete return type, but the per-variant arms
produce `&NumericIndexInner<T>`, `&MapIndex<K>`, `&GeoMapIndex`, etc.
— different types. A unifying borrowed-enum (à la FacetIndexEnum)
would be more code than the trait-object indirection saves.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack
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: 5de75487-705f-4c83-8481-6a82c1db0152

📥 Commits

Reviewing files that changed from the base of the PR and between 530bca6 and ee644f3.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/field_index_base/field_index_read.rs
  • lib/segment/src/index/field_index/field_index_base/payload_field_index.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/segment/src/index/field_index/field_index_base/payload_field_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index_read.rs

📝 Walkthrough

Walkthrough

This PR refactors the field index read architecture by introducing a polymorphic dispatch mechanism. The FieldIndexRead trait gains a required get_payload_field_index_read() method that exposes the underlying PayloadFieldIndexRead implementation. Previously concrete methods (count_indexed_points, filter, estimate_cardinality, for_each_payload_block) transition to default implementations that delegate through this accessor. Both traits gain a new condition_checker() method that enables index-specific condition evaluation. The condition converter helper is updated to attempt polymorphic dispatch before falling back to legacy pattern matching.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • qdrant/qdrant#8976: Modifies FieldIndex read-side API and delegations; closely related to these trait/impl changes.
  • qdrant/qdrant#8975: Evolves FieldIndexRead surface and is directly related to the accessor/delegation refactor present here.
  • qdrant/qdrant#8939: Overlaps FullTextIndex matching/condition logic that the new condition_checker paths wire into.

Suggested reviewers

  • coszio
  • timvisee
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a condition_checker trait method to PayloadFieldIndexRead as a foundation for the larger refactoring.
Description check ✅ Passed The description is well-organized and directly related to the changeset. It explains the summary, what changed, architectural rationale, and includes test plan—all matching the raw_summary and code modifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 condition-checker-trait

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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@lib/segment/src/index/field_index/field_index_base/field_index_read.rs`:
- Line 39: Update the documentation comment in field_index_read.rs that
currently reads "implementors" to the correct spelling "implementers"; locate
the doc comment above the default implementation helpers (the line that starts
with "Used internally by the default impls below — implementors typically") and
replace only that word so codespell no longer flags the file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f7f9625-3b37-48e2-a905-ab215e10f990

📥 Commits

Reviewing files that changed from the base of the PR and between 4a76439 and 3a7f4ab.

📒 Files selected for processing (4)
  • lib/segment/src/index/field_index/field_index_base/field_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index_read.rs
  • lib/segment/src/index/field_index/field_index_base/payload_field_index.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs

generall added a commit that referenced this pull request May 10, 2026
…tion_checker

Sub-plan PR 4 of the condition-checker-migration. MapIndex<K> now
serves Match::Value / Match::Any / Match::Except conditions directly
through PayloadFieldIndexRead::condition_checker, one override per K
(MapIndex<str>, MapIndex<UuidIntType>, MapIndex<IntPayloadType>).

Changes:

1. Three impl blocks gain condition_checker overrides — one per K.
   Each uses an explicit FieldCondition destructure (no `..`) and an
   exhaustive `Match` variant match (no `_ => None`); a new variant
   in FieldCondition, Match, ValueVariants, or AnyVariants forces a
   compile error in every relevant place. INDEXSET_ITER_THRESHOLD
   small/large branching preserved.

2. read_view/condition_converter/match_converter.rs sheds the Map
   arms. get_match_value_checker keeps (Bool, BoolIndex) plus the
   explicit 30-tuple None list. get_match_any_checker becomes an
   explicit 22-tuple None match (no Bool/FullText/Numeric/Geo/Null
   variant ever served Any). get_match_except_checker reduces to the
   unconditional values_count > 0 fallback — when no typed index
   handles Except (via condition_checker), match any point with at
   least one value, since the value can't be in a type-mismatched
   list. Unused IndexSet/Uuid/INDEXSET_ITER_THRESHOLD imports drop.

Stacked on #8981 (NumericIndex) → #8980 (NullIndex) → #8979
(GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
…ndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
…rs (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
…8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
* refactor(field_index): migrate BoolIndex condition checking into condition_checker

Sub-plan PR 5 of the condition-checker-migration. BoolIndex now
serves `Match::Value(Bool)` directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for BoolIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) plus an
   exhaustive `Match` variant match (no `_ => None`). Match::Any /
   Match::Except over booleans return None — matches legacy
   match_converter behaviour.

2. read_view/condition_converter/match_converter.rs's
   get_match_value_checker drops the `(Bool, BoolIndex)` arm; the
   function now returns None unconditionally for every (value, index)
   pair, with the explicit 33-tuple list preserved so adding a new
   ValueVariants or FieldIndex variant forces a compile error.

Stacked on #8982 (MapIndex) → #8981 → #8980 → #8979 → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate FullTextIndex into condition_checker (#8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
* refactor(field_index): migrate MapIndex condition checking into condition_checker

Sub-plan PR 4 of the condition-checker-migration. MapIndex<K> now
serves Match::Value / Match::Any / Match::Except conditions directly
through PayloadFieldIndexRead::condition_checker, one override per K
(MapIndex<str>, MapIndex<UuidIntType>, MapIndex<IntPayloadType>).

Changes:

1. Three impl blocks gain condition_checker overrides — one per K.
   Each uses an explicit FieldCondition destructure (no `..`) and an
   exhaustive `Match` variant match (no `_ => None`); a new variant
   in FieldCondition, Match, ValueVariants, or AnyVariants forces a
   compile error in every relevant place. INDEXSET_ITER_THRESHOLD
   small/large branching preserved.

2. read_view/condition_converter/match_converter.rs sheds the Map
   arms. get_match_value_checker keeps (Bool, BoolIndex) plus the
   explicit 30-tuple None list. get_match_any_checker becomes an
   explicit 22-tuple None match (no Bool/FullText/Numeric/Geo/Null
   variant ever served Any). get_match_except_checker reduces to the
   unconditional values_count > 0 fallback — when no typed index
   handles Except (via condition_checker), match any point with at
   least one value, since the value can't be in a type-mismatched
   list. Unused IndexSet/Uuid/INDEXSET_ITER_THRESHOLD imports drop.

Stacked on #8981 (NumericIndex) → #8980 (NullIndex) → #8979
(GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate BoolIndex into condition_checker (#8983)

* refactor(field_index): migrate BoolIndex condition checking into condition_checker

Sub-plan PR 5 of the condition-checker-migration. BoolIndex now
serves `Match::Value(Bool)` directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for BoolIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) plus an
   exhaustive `Match` variant match (no `_ => None`). Match::Any /
   Match::Except over booleans return None — matches legacy
   match_converter behaviour.

2. read_view/condition_converter/match_converter.rs's
   get_match_value_checker drops the `(Bool, BoolIndex)` arm; the
   function now returns None unconditionally for every (value, index)
   pair, with the explicit 33-tuple list preserved so adding a new
   ValueVariants or FieldIndex variant forces a compile error.

Stacked on #8982 (MapIndex) → #8981 → #8980 → #8979 → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate FullTextIndex into condition_checker (#8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
…8981)

* refactor(field_index): migrate NumericIndex condition checking into condition_checker

Sub-plan PR 3 of the condition-checker-migration. NumericIndexInner<T>
now serves Range conditions directly through
PayloadFieldIndexRead::condition_checker. The generic impl handles all
four FieldIndex variants (IntIndex, FloatIndex, DatetimeIndex,
UuidIndex) with one trait override.

Changes:

1. impl PayloadFieldIndexRead for NumericIndexInner<T> gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) binds `range`. Body converts the RangeInterface bounds
   into T via T::from_f64 / T::from_u128 — same conversion `filter`
   already uses.

2. read_view/condition_converter/helpers.rs drops the range arm from
   field_condition_index's legacy match and deletes
   get_range_checkers / get_float_range_checkers /
   get_datetime_range_checkers (3 helpers, ~75 lines). Six unused
   imports go with them.

Behavioural note: The legacy helpers were stricter than `filter` —
only IntIndex/FloatIndex served Float ranges, only DatetimeIndex
served DateTime ranges; UuidIndex returned None. `filter` already
handles every numeric variant uniformly via T::from_f64 / T::from_u128,
so there was a pre-existing inconsistency between filter (primary-
clause iteration) and condition_checker (post-filter validation).
This PR makes condition_checker match filter — every NumericIndex
variant can now serve any RangeInterface. The schema layer normally
prevents cross-type range queries from reaching here.

Stacked on #8980 (NullIndex) → #8979 (GeoMapIndex) → #8978
(foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate MapIndex into condition_checker (#8982)

* refactor(field_index): migrate MapIndex condition checking into condition_checker

Sub-plan PR 4 of the condition-checker-migration. MapIndex<K> now
serves Match::Value / Match::Any / Match::Except conditions directly
through PayloadFieldIndexRead::condition_checker, one override per K
(MapIndex<str>, MapIndex<UuidIntType>, MapIndex<IntPayloadType>).

Changes:

1. Three impl blocks gain condition_checker overrides — one per K.
   Each uses an explicit FieldCondition destructure (no `..`) and an
   exhaustive `Match` variant match (no `_ => None`); a new variant
   in FieldCondition, Match, ValueVariants, or AnyVariants forces a
   compile error in every relevant place. INDEXSET_ITER_THRESHOLD
   small/large branching preserved.

2. read_view/condition_converter/match_converter.rs sheds the Map
   arms. get_match_value_checker keeps (Bool, BoolIndex) plus the
   explicit 30-tuple None list. get_match_any_checker becomes an
   explicit 22-tuple None match (no Bool/FullText/Numeric/Geo/Null
   variant ever served Any). get_match_except_checker reduces to the
   unconditional values_count > 0 fallback — when no typed index
   handles Except (via condition_checker), match any point with at
   least one value, since the value can't be in a type-mismatched
   list. Unused IndexSet/Uuid/INDEXSET_ITER_THRESHOLD imports drop.

Stacked on #8981 (NumericIndex) → #8980 (NullIndex) → #8979
(GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate BoolIndex into condition_checker (#8983)

* refactor(field_index): migrate BoolIndex condition checking into condition_checker

Sub-plan PR 5 of the condition-checker-migration. BoolIndex now
serves `Match::Value(Bool)` directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for BoolIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) plus an
   exhaustive `Match` variant match (no `_ => None`). Match::Any /
   Match::Except over booleans return None — matches legacy
   match_converter behaviour.

2. read_view/condition_converter/match_converter.rs's
   get_match_value_checker drops the `(Bool, BoolIndex)` arm; the
   function now returns None unconditionally for every (value, index)
   pair, with the explicit 33-tuple list preserved so adding a new
   ValueVariants or FieldIndex variant forces a compile error.

Stacked on #8982 (MapIndex) → #8981 → #8980 → #8979 → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate FullTextIndex into condition_checker (#8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 11, 2026
* refactor(field_index): migrate NullIndex condition checking into condition_checker

Sub-plan PR 2 of the condition-checker-migration. NullIndex now
serves is_empty / is_null conditions directly through
PayloadFieldIndexRead::condition_checker. The dispatch in the read
view's condition_converter/mod.rs collapses to mirror the
Condition::Field arm: try every index for the field, fall back to
the payload check on unwrap_or_else.

Changes:

1. impl PayloadFieldIndexRead for NullIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) — binds
   is_empty and is_null, every other field uses `_:` to document
   intentional non-handling.

2. read_view/condition_converter/helpers.rs drops the is_empty /
   is_null arms from field_condition_index's legacy match and deletes
   five orphaned helpers: get_is_empty_checker, get_is_null_checker,
   get_is_empty_indexes, get_null_index_is_empty_checker,
   get_fallback_is_empty_checker.

3. read_view/condition_converter/mod.rs rewrites Condition::IsEmpty
   and Condition::IsNull to use field_condition_index with a
   constructed FieldCondition, same shape as Condition::Field.

Behavioural note (decision locked during review): The legacy
values_is_empty fast-path for "field has indexes but no NullIndex"
is dropped. NullIndex was introduced in v1.13.5 (#6088); we're on
v1.18.0, so any collection touched in the past ~5 minor releases has
a NullIndex. Segments untouched since pre-v1.13.5 fall through to the
payload check on is_empty queries — no longer accelerated by another
index's values_is_empty. A re-index recovers the original perf.

Stacked on #8979 (GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate NumericIndex into condition_checker (#8981)

* refactor(field_index): migrate NumericIndex condition checking into condition_checker

Sub-plan PR 3 of the condition-checker-migration. NumericIndexInner<T>
now serves Range conditions directly through
PayloadFieldIndexRead::condition_checker. The generic impl handles all
four FieldIndex variants (IntIndex, FloatIndex, DatetimeIndex,
UuidIndex) with one trait override.

Changes:

1. impl PayloadFieldIndexRead for NumericIndexInner<T> gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) binds `range`. Body converts the RangeInterface bounds
   into T via T::from_f64 / T::from_u128 — same conversion `filter`
   already uses.

2. read_view/condition_converter/helpers.rs drops the range arm from
   field_condition_index's legacy match and deletes
   get_range_checkers / get_float_range_checkers /
   get_datetime_range_checkers (3 helpers, ~75 lines). Six unused
   imports go with them.

Behavioural note: The legacy helpers were stricter than `filter` —
only IntIndex/FloatIndex served Float ranges, only DatetimeIndex
served DateTime ranges; UuidIndex returned None. `filter` already
handles every numeric variant uniformly via T::from_f64 / T::from_u128,
so there was a pre-existing inconsistency between filter (primary-
clause iteration) and condition_checker (post-filter validation).
This PR makes condition_checker match filter — every NumericIndex
variant can now serve any RangeInterface. The schema layer normally
prevents cross-type range queries from reaching here.

Stacked on #8980 (NullIndex) → #8979 (GeoMapIndex) → #8978
(foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate MapIndex into condition_checker (#8982)

* refactor(field_index): migrate MapIndex condition checking into condition_checker

Sub-plan PR 4 of the condition-checker-migration. MapIndex<K> now
serves Match::Value / Match::Any / Match::Except conditions directly
through PayloadFieldIndexRead::condition_checker, one override per K
(MapIndex<str>, MapIndex<UuidIntType>, MapIndex<IntPayloadType>).

Changes:

1. Three impl blocks gain condition_checker overrides — one per K.
   Each uses an explicit FieldCondition destructure (no `..`) and an
   exhaustive `Match` variant match (no `_ => None`); a new variant
   in FieldCondition, Match, ValueVariants, or AnyVariants forces a
   compile error in every relevant place. INDEXSET_ITER_THRESHOLD
   small/large branching preserved.

2. read_view/condition_converter/match_converter.rs sheds the Map
   arms. get_match_value_checker keeps (Bool, BoolIndex) plus the
   explicit 30-tuple None list. get_match_any_checker becomes an
   explicit 22-tuple None match (no Bool/FullText/Numeric/Geo/Null
   variant ever served Any). get_match_except_checker reduces to the
   unconditional values_count > 0 fallback — when no typed index
   handles Except (via condition_checker), match any point with at
   least one value, since the value can't be in a type-mismatched
   list. Unused IndexSet/Uuid/INDEXSET_ITER_THRESHOLD imports drop.

Stacked on #8981 (NumericIndex) → #8980 (NullIndex) → #8979
(GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate BoolIndex into condition_checker (#8983)

* refactor(field_index): migrate BoolIndex condition checking into condition_checker

Sub-plan PR 5 of the condition-checker-migration. BoolIndex now
serves `Match::Value(Bool)` directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for BoolIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) plus an
   exhaustive `Match` variant match (no `_ => None`). Match::Any /
   Match::Except over booleans return None — matches legacy
   match_converter behaviour.

2. read_view/condition_converter/match_converter.rs's
   get_match_value_checker drops the `(Bool, BoolIndex)` arm; the
   function now returns None unconditionally for every (value, index)
   pair, with the explicit 33-tuple list preserved so adding a new
   ValueVariants or FieldIndex variant forces a compile error.

Stacked on #8982 (MapIndex) → #8981 → #8980 → #8979 → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate FullTextIndex into condition_checker (#8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
)

* refactor(field_index): migrate GeoMapIndex condition checking into condition_checker

Sub-plan PR 1 of the condition-checker-migration. GeoMapIndex now
serves geo conditions (geo_radius, geo_bounding_box, geo_polygon)
directly through PayloadFieldIndexRead::condition_checker. The
corresponding match arms and three helper functions in the read
view's helpers.rs are gone — the polymorphic dispatch in
field_condition_index handles them.

Changes:

1. impl PayloadFieldIndexRead for GeoMapIndex gains a condition_checker
   override. Bodies copied from get_geo_radius_checkers /
   get_geo_bounding_box_checkers / get_geo_polygon_checkers; the
   `&'a self` capture replaces the &FieldIndex match arm.

2. The override destructures FieldCondition explicitly (no `..`,
   every field named with either a binding or `_:`). This forces a
   compile error if a new field is added to FieldCondition, so each
   index variant must explicitly decide whether to handle it. Same
   pattern is mandated for the remaining variant migrations — see
   docs/plans/field-index-read-trait/condition-checker-migration/00-overview.md.

3. read_view/condition_converter/helpers.rs drops the three Geo
   FieldCondition arms from field_condition_index's legacy match
   and deletes the three helper functions. The catch-all is relaxed
   to `geo_radius: _ | geo_bounding_box: _ | geo_polygon: _` since
   the trait method handles all geo cases now.

No behavioural change: non-Geo variants continue to return None for
geo conditions (the trait default returns None), and the read view's
catch-all still falls back to the payload check.

Stacked on #8978 (condition-checker-trait foundation).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate NullIndex into condition_checker (#8980)

* refactor(field_index): migrate NullIndex condition checking into condition_checker

Sub-plan PR 2 of the condition-checker-migration. NullIndex now
serves is_empty / is_null conditions directly through
PayloadFieldIndexRead::condition_checker. The dispatch in the read
view's condition_converter/mod.rs collapses to mirror the
Condition::Field arm: try every index for the field, fall back to
the payload check on unwrap_or_else.

Changes:

1. impl PayloadFieldIndexRead for NullIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) — binds
   is_empty and is_null, every other field uses `_:` to document
   intentional non-handling.

2. read_view/condition_converter/helpers.rs drops the is_empty /
   is_null arms from field_condition_index's legacy match and deletes
   five orphaned helpers: get_is_empty_checker, get_is_null_checker,
   get_is_empty_indexes, get_null_index_is_empty_checker,
   get_fallback_is_empty_checker.

3. read_view/condition_converter/mod.rs rewrites Condition::IsEmpty
   and Condition::IsNull to use field_condition_index with a
   constructed FieldCondition, same shape as Condition::Field.

Behavioural note (decision locked during review): The legacy
values_is_empty fast-path for "field has indexes but no NullIndex"
is dropped. NullIndex was introduced in v1.13.5 (#6088); we're on
v1.18.0, so any collection touched in the past ~5 minor releases has
a NullIndex. Segments untouched since pre-v1.13.5 fall through to the
payload check on is_empty queries — no longer accelerated by another
index's values_is_empty. A re-index recovers the original perf.

Stacked on #8979 (GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate NumericIndex into condition_checker (#8981)

* refactor(field_index): migrate NumericIndex condition checking into condition_checker

Sub-plan PR 3 of the condition-checker-migration. NumericIndexInner<T>
now serves Range conditions directly through
PayloadFieldIndexRead::condition_checker. The generic impl handles all
four FieldIndex variants (IntIndex, FloatIndex, DatetimeIndex,
UuidIndex) with one trait override.

Changes:

1. impl PayloadFieldIndexRead for NumericIndexInner<T> gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) binds `range`. Body converts the RangeInterface bounds
   into T via T::from_f64 / T::from_u128 — same conversion `filter`
   already uses.

2. read_view/condition_converter/helpers.rs drops the range arm from
   field_condition_index's legacy match and deletes
   get_range_checkers / get_float_range_checkers /
   get_datetime_range_checkers (3 helpers, ~75 lines). Six unused
   imports go with them.

Behavioural note: The legacy helpers were stricter than `filter` —
only IntIndex/FloatIndex served Float ranges, only DatetimeIndex
served DateTime ranges; UuidIndex returned None. `filter` already
handles every numeric variant uniformly via T::from_f64 / T::from_u128,
so there was a pre-existing inconsistency between filter (primary-
clause iteration) and condition_checker (post-filter validation).
This PR makes condition_checker match filter — every NumericIndex
variant can now serve any RangeInterface. The schema layer normally
prevents cross-type range queries from reaching here.

Stacked on #8980 (NullIndex) → #8979 (GeoMapIndex) → #8978
(foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate MapIndex into condition_checker (#8982)

* refactor(field_index): migrate MapIndex condition checking into condition_checker

Sub-plan PR 4 of the condition-checker-migration. MapIndex<K> now
serves Match::Value / Match::Any / Match::Except conditions directly
through PayloadFieldIndexRead::condition_checker, one override per K
(MapIndex<str>, MapIndex<UuidIntType>, MapIndex<IntPayloadType>).

Changes:

1. Three impl blocks gain condition_checker overrides — one per K.
   Each uses an explicit FieldCondition destructure (no `..`) and an
   exhaustive `Match` variant match (no `_ => None`); a new variant
   in FieldCondition, Match, ValueVariants, or AnyVariants forces a
   compile error in every relevant place. INDEXSET_ITER_THRESHOLD
   small/large branching preserved.

2. read_view/condition_converter/match_converter.rs sheds the Map
   arms. get_match_value_checker keeps (Bool, BoolIndex) plus the
   explicit 30-tuple None list. get_match_any_checker becomes an
   explicit 22-tuple None match (no Bool/FullText/Numeric/Geo/Null
   variant ever served Any). get_match_except_checker reduces to the
   unconditional values_count > 0 fallback — when no typed index
   handles Except (via condition_checker), match any point with at
   least one value, since the value can't be in a type-mismatched
   list. Unused IndexSet/Uuid/INDEXSET_ITER_THRESHOLD imports drop.

Stacked on #8981 (NumericIndex) → #8980 (NullIndex) → #8979
(GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate BoolIndex into condition_checker (#8983)

* refactor(field_index): migrate BoolIndex condition checking into condition_checker

Sub-plan PR 5 of the condition-checker-migration. BoolIndex now
serves `Match::Value(Bool)` directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for BoolIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) plus an
   exhaustive `Match` variant match (no `_ => None`). Match::Any /
   Match::Except over booleans return None — matches legacy
   match_converter behaviour.

2. read_view/condition_converter/match_converter.rs's
   get_match_value_checker drops the `(Bool, BoolIndex)` arm; the
   function now returns None unconditionally for every (value, index)
   pair, with the explicit 33-tuple list preserved so adding a new
   ValueVariants or FieldIndex variant forces a compile error.

Stacked on #8982 (MapIndex) → #8981 → #8980 → #8979 → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate FullTextIndex into condition_checker (#8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

@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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/segment/src/index/struct_payload_index/read_view/condition_converter.rs (1)

35-43: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Don't treat partial index checkers as full FieldCondition evaluators.

At Line 35, any Some from index.condition_checker(...) bypasses check_field_condition, but the new checker implementations only validate the one sub-shape they optimize and ignore other populated members of FieldCondition. That means composite conditions like match && values_count or is_empty && is_null == false can now short-circuit to a predicate that checks only half the condition and return wrong matches. Please require condition_checker() to return None unless it fully covers the entire FieldCondition, or keep the full-condition fallback for mixed shapes here.

🤖 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/struct_payload_index/read_view/condition_converter.rs`
around lines 35 - 43, The current branch in Condition::Field accepts any Some
from index.condition_checker(...) which allows partial checkers to
short-circuit; change this so you only use the returned checker when it declares
full coverage of the provided FieldCondition. Concretely, update the logic
around field_indexes.get(...).and_then(...){
index.condition_checker(field_condition, hw_acc) } to call the returned checker
only if it reports full coverage (e.g., checker.fully_covers(&field_condition)
or an equivalent boolean on the returned type); otherwise ignore that Some and
continue to the unwrap_or_else fallback that invokes check_field_condition for
full evaluation. Ensure you reference index.condition_checker, the returned
checker’s coverage check (e.g., fully_covers), and the fallback
check_field_condition so partial checkers never short-circuit complete
FieldCondition evaluation.
🤖 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.

Inline comments:
In `@lib/segment/src/index/field_index/field_index_base/payload_field_index.rs`:
- Around line 47-57: The trait method condition_checker in PayloadFieldIndexRead
currently has no default implementation which forces all implementers to
override it; provide the documented default body by implementing
condition_checker<'a>(&'a self, _condition: &FieldCondition, _hw_acc:
HwMeasurementAcc) -> Option<ConditionCheckerFn<'a>> that simply returns None so
implementers without an optimized checker can inherit the default; update the
method signature in the trait (condition_checker) to include this default return
and ensure types and doc comment references to FieldCondition, HwMeasurementAcc,
and ConditionCheckerFn remain unchanged.

---

Outside diff comments:
In `@lib/segment/src/index/struct_payload_index/read_view/condition_converter.rs`:
- Around line 35-43: The current branch in Condition::Field accepts any Some
from index.condition_checker(...) which allows partial checkers to
short-circuit; change this so you only use the returned checker when it declares
full coverage of the provided FieldCondition. Concretely, update the logic
around field_indexes.get(...).and_then(...){
index.condition_checker(field_condition, hw_acc) } to call the returned checker
only if it reports full coverage (e.g., checker.fully_covers(&field_condition)
or an equivalent boolean on the returned type); otherwise ignore that Some and
continue to the unwrap_or_else fallback that invokes check_field_condition for
full evaluation. Ensure you reference index.condition_checker, the returned
checker’s coverage check (e.g., fully_covers), and the fallback
check_field_condition so partial checkers never short-circuit complete
FieldCondition evaluation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ea6eaf31-0f8a-4764-8ccd-ee0a5e89820f

📥 Commits

Reviewing files that changed from the base of the PR and between 3a7f4ab and 530bca6.

📒 Files selected for processing (17)
  • lib/segment/src/index/field_index/bool_index/immutable_bool_index.rs
  • lib/segment/src/index/field_index/bool_index/mod.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index_read.rs
  • lib/segment/src/index/field_index/field_index_base/payload_field_index.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/index/field_index/geo_index/mod.rs
  • lib/segment/src/index/field_index/map_index/mod.rs
  • lib/segment/src/index/field_index/null_index/immutable_null_index.rs
  • lib/segment/src/index/field_index/null_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/match_converter.rs
  • lib/segment/src/index/struct_payload_index/read_view/value_retriever/helpers.rs
💤 Files with no reviewable changes (2)
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/match_converter.rs

Comment on lines +47 to +57
/// Convert a field condition into a per-point checker closure, if this
/// index can serve the condition.
///
/// Returns `None` when the condition is not one this index understands —
/// the default impl returns `None` so types that don't override it
/// fall through to whatever dispatcher the caller layered on top.
fn condition_checker<'a>(
&'a self,
_condition: &FieldCondition,
_hw_acc: HwMeasurementAcc,
) -> Option<ConditionCheckerFn<'a>>;

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Give condition_checker the documented default body.

On Line 53 this is still a required trait method, so every PayloadFieldIndexRead implementer now has to change even when it has no optimized checker. That makes this refactor an avoidable API break and contradicts the doc comment above it.

Suggested fix
     fn condition_checker<'a>(
         &'a self,
         _condition: &FieldCondition,
         _hw_acc: HwMeasurementAcc,
-    ) -> Option<ConditionCheckerFn<'a>>;
+    ) -> Option<ConditionCheckerFn<'a>> {
+        None
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Convert a field condition into a per-point checker closure, if this
/// index can serve the condition.
///
/// Returns `None` when the condition is not one this index understands —
/// the default impl returns `None` so types that don't override it
/// fall through to whatever dispatcher the caller layered on top.
fn condition_checker<'a>(
&'a self,
_condition: &FieldCondition,
_hw_acc: HwMeasurementAcc,
) -> Option<ConditionCheckerFn<'a>>;
/// Convert a field condition into a per-point checker closure, if this
/// index can serve the condition.
///
/// Returns `None` when the condition is not one this index understands —
/// the default impl returns `None` so types that don't override it
/// fall through to whatever dispatcher the caller layered on top.
fn condition_checker<'a>(
&'a self,
_condition: &FieldCondition,
_hw_acc: HwMeasurementAcc,
) -> Option<ConditionCheckerFn<'a>> {
None
}
🤖 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/field_index_base/payload_field_index.rs`
around lines 47 - 57, The trait method condition_checker in
PayloadFieldIndexRead currently has no default implementation which forces all
implementers to override it; provide the documented default body by implementing
condition_checker<'a>(&'a self, _condition: &FieldCondition, _hw_acc:
HwMeasurementAcc) -> Option<ConditionCheckerFn<'a>> that simply returns None so
implementers without an optimized checker can inherit the default; update the
method signature in the trait (condition_checker) to include this default return
and ensure types and doc comment references to FieldCondition, HwMeasurementAcc,
and ConditionCheckerFn remain unchanged.

generall added a commit that referenced this pull request May 22, 2026
#8978)

* refactor(field_index): add condition_checker trait method (foundation)

First PR in the condition-checker-migration sub-plan
(docs/plans/field-index-read-trait/condition-checker-migration/).
Purely additive: every existing typed index keeps the default `None`
impl, so the legacy match in `field_condition_index` handles every
condition. Behaviour unchanged.

Changes:

1. PayloadFieldIndexRead::condition_checker — new method with default
   `None` body. Lets each typed index advertise the conditions it can
   serve.

2. FieldIndexRead::get_payload_field_index_read — new required method
   returning `&dyn PayloadFieldIndexRead`. Distinct from the existing
   inherent `get_payload_field_index` (which returns `&dyn PayloadFieldIndex`,
   exposing write-side methods) — the read path now hands back a
   handle that can't accidentally call wipe / flusher / files.

3. Five pure-delegation methods on FieldIndexRead get default impls
   using the new getter (count_indexed_points, filter,
   estimate_cardinality, for_each_payload_block, condition_checker).
   `impl FieldIndexRead for FieldIndex` drops their explicit bodies.

4. field_condition_index in read_view/condition_converter/helpers.rs
   tries `index.condition_checker(...)` first, then falls through to
   the existing legacy match. The match handles everything until
   per-variant overrides land in the follow-up PRs.

Why `&dyn` rather than `impl PayloadFieldIndexRead + '_`: RPITIT
requires a single concrete return type, but the per-variant arms
produce `&NumericIndexInner<T>`, `&MapIndex<K>`, `&GeoMapIndex`, etc.
— different types. A unifying borrowed-enum (à la FacetIndexEnum)
would be more code than the trait-object indirection saves.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate GeoMapIndex into condition_checker (#8979)

* refactor(field_index): migrate GeoMapIndex condition checking into condition_checker

Sub-plan PR 1 of the condition-checker-migration. GeoMapIndex now
serves geo conditions (geo_radius, geo_bounding_box, geo_polygon)
directly through PayloadFieldIndexRead::condition_checker. The
corresponding match arms and three helper functions in the read
view's helpers.rs are gone — the polymorphic dispatch in
field_condition_index handles them.

Changes:

1. impl PayloadFieldIndexRead for GeoMapIndex gains a condition_checker
   override. Bodies copied from get_geo_radius_checkers /
   get_geo_bounding_box_checkers / get_geo_polygon_checkers; the
   `&'a self` capture replaces the &FieldIndex match arm.

2. The override destructures FieldCondition explicitly (no `..`,
   every field named with either a binding or `_:`). This forces a
   compile error if a new field is added to FieldCondition, so each
   index variant must explicitly decide whether to handle it. Same
   pattern is mandated for the remaining variant migrations — see
   docs/plans/field-index-read-trait/condition-checker-migration/00-overview.md.

3. read_view/condition_converter/helpers.rs drops the three Geo
   FieldCondition arms from field_condition_index's legacy match
   and deletes the three helper functions. The catch-all is relaxed
   to `geo_radius: _ | geo_bounding_box: _ | geo_polygon: _` since
   the trait method handles all geo cases now.

No behavioural change: non-Geo variants continue to return None for
geo conditions (the trait default returns None), and the read view's
catch-all still falls back to the payload check.

Stacked on #8978 (condition-checker-trait foundation).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate NullIndex into condition_checker (#8980)

* refactor(field_index): migrate NullIndex condition checking into condition_checker

Sub-plan PR 2 of the condition-checker-migration. NullIndex now
serves is_empty / is_null conditions directly through
PayloadFieldIndexRead::condition_checker. The dispatch in the read
view's condition_converter/mod.rs collapses to mirror the
Condition::Field arm: try every index for the field, fall back to
the payload check on unwrap_or_else.

Changes:

1. impl PayloadFieldIndexRead for NullIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) — binds
   is_empty and is_null, every other field uses `_:` to document
   intentional non-handling.

2. read_view/condition_converter/helpers.rs drops the is_empty /
   is_null arms from field_condition_index's legacy match and deletes
   five orphaned helpers: get_is_empty_checker, get_is_null_checker,
   get_is_empty_indexes, get_null_index_is_empty_checker,
   get_fallback_is_empty_checker.

3. read_view/condition_converter/mod.rs rewrites Condition::IsEmpty
   and Condition::IsNull to use field_condition_index with a
   constructed FieldCondition, same shape as Condition::Field.

Behavioural note (decision locked during review): The legacy
values_is_empty fast-path for "field has indexes but no NullIndex"
is dropped. NullIndex was introduced in v1.13.5 (#6088); we're on
v1.18.0, so any collection touched in the past ~5 minor releases has
a NullIndex. Segments untouched since pre-v1.13.5 fall through to the
payload check on is_empty queries — no longer accelerated by another
index's values_is_empty. A re-index recovers the original perf.

Stacked on #8979 (GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate NumericIndex into condition_checker (#8981)

* refactor(field_index): migrate NumericIndex condition checking into condition_checker

Sub-plan PR 3 of the condition-checker-migration. NumericIndexInner<T>
now serves Range conditions directly through
PayloadFieldIndexRead::condition_checker. The generic impl handles all
four FieldIndex variants (IntIndex, FloatIndex, DatetimeIndex,
UuidIndex) with one trait override.

Changes:

1. impl PayloadFieldIndexRead for NumericIndexInner<T> gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) binds `range`. Body converts the RangeInterface bounds
   into T via T::from_f64 / T::from_u128 — same conversion `filter`
   already uses.

2. read_view/condition_converter/helpers.rs drops the range arm from
   field_condition_index's legacy match and deletes
   get_range_checkers / get_float_range_checkers /
   get_datetime_range_checkers (3 helpers, ~75 lines). Six unused
   imports go with them.

Behavioural note: The legacy helpers were stricter than `filter` —
only IntIndex/FloatIndex served Float ranges, only DatetimeIndex
served DateTime ranges; UuidIndex returned None. `filter` already
handles every numeric variant uniformly via T::from_f64 / T::from_u128,
so there was a pre-existing inconsistency between filter (primary-
clause iteration) and condition_checker (post-filter validation).
This PR makes condition_checker match filter — every NumericIndex
variant can now serve any RangeInterface. The schema layer normally
prevents cross-type range queries from reaching here.

Stacked on #8980 (NullIndex) → #8979 (GeoMapIndex) → #8978
(foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate MapIndex into condition_checker (#8982)

* refactor(field_index): migrate MapIndex condition checking into condition_checker

Sub-plan PR 4 of the condition-checker-migration. MapIndex<K> now
serves Match::Value / Match::Any / Match::Except conditions directly
through PayloadFieldIndexRead::condition_checker, one override per K
(MapIndex<str>, MapIndex<UuidIntType>, MapIndex<IntPayloadType>).

Changes:

1. Three impl blocks gain condition_checker overrides — one per K.
   Each uses an explicit FieldCondition destructure (no `..`) and an
   exhaustive `Match` variant match (no `_ => None`); a new variant
   in FieldCondition, Match, ValueVariants, or AnyVariants forces a
   compile error in every relevant place. INDEXSET_ITER_THRESHOLD
   small/large branching preserved.

2. read_view/condition_converter/match_converter.rs sheds the Map
   arms. get_match_value_checker keeps (Bool, BoolIndex) plus the
   explicit 30-tuple None list. get_match_any_checker becomes an
   explicit 22-tuple None match (no Bool/FullText/Numeric/Geo/Null
   variant ever served Any). get_match_except_checker reduces to the
   unconditional values_count > 0 fallback — when no typed index
   handles Except (via condition_checker), match any point with at
   least one value, since the value can't be in a type-mismatched
   list. Unused IndexSet/Uuid/INDEXSET_ITER_THRESHOLD imports drop.

Stacked on #8981 (NumericIndex) → #8980 (NullIndex) → #8979
(GeoMapIndex) → #8978 (foundation) → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate BoolIndex into condition_checker (#8983)

* refactor(field_index): migrate BoolIndex condition checking into condition_checker

Sub-plan PR 5 of the condition-checker-migration. BoolIndex now
serves `Match::Value(Bool)` directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for BoolIndex gains a condition_checker
   override. Explicit FieldCondition destructure (no `..`) plus an
   exhaustive `Match` variant match (no `_ => None`). Match::Any /
   Match::Except over booleans return None — matches legacy
   match_converter behaviour.

2. read_view/condition_converter/match_converter.rs's
   get_match_value_checker drops the `(Bool, BoolIndex)` arm; the
   function now returns None unconditionally for every (value, index)
   pair, with the explicit 33-tuple list preserved so adding a new
   ValueVariants or FieldIndex variant forces a compile error.

Stacked on #8982 (MapIndex) → #8981 → #8980 → #8979 → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate FullTextIndex into condition_checker (#8984)

* refactor(field_index): migrate FullTextIndex condition checking into condition_checker

Sub-plan PR 6 of the condition-checker-migration. FullTextIndex now
serves Match::Text / Match::TextAny / Match::Phrase directly through
PayloadFieldIndexRead::condition_checker.

Changes:

1. impl PayloadFieldIndexRead for FullTextIndex gains a
   condition_checker override. Explicit FieldCondition destructure
   (no `..`) plus exhaustive Match variant matching (no `_ => None`).
   Match::Value / Match::Any / Match::Except all return None
   explicitly. Body copies parse_text_query / parse_phrase_query /
   parse_text_any_query dispatch and the check_match closure from the
   legacy helper, preserving the FIXME-marked error swallowing.

2. read_view/condition_converter/match_converter.rs loses
   get_match_text_checker and the TextQueryType enum (both
   unused after this PR). get_match_checkers' Text/TextAny/Phrase
   arms collapse to a single explicit `None` arm.

Stacked on #8983 (BoolIndex) → #8982 (MapIndex) → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): remove legacy condition_checker dispatch helpers (#8985)

* refactor(field_index): remove legacy condition_checker dispatch helpers

Final PR (7) of the condition-checker-migration sub-plan. With every
typed FieldIndex variant now serving its conditions via
PayloadFieldIndexRead::condition_checker (PRs 1-6), the wrapper
`field_condition_index` and the legacy match dispatch are no longer
needed.

Changes:

1. read_view/condition_converter/mod.rs's three call sites
   (Condition::Field, Condition::IsEmpty, Condition::IsNull) call
   `index.condition_checker(...)` directly instead of going through
   the `field_condition_index` wrapper.

2. helpers.rs (49 lines) and match_converter.rs (119 lines) deleted —
   `field_condition_index`, `get_match_checkers`,
   `get_match_value_checker`, `get_match_any_checker`,
   `get_match_except_checker` are all gone.

3. The directory `condition_converter/` collapses to a flat file
   `condition_converter.rs` (mod.rs renamed via git).

Behavioural note: the legacy `Match::Except` `values_count > 0`
fallback for type-mismatched Except queries is no longer applied —
those now fall through to the payload check via
`check_field_condition`. Schema-level type checking prevents
cross-type Match::Except queries from reaching here in practice, so
the fallback was only useful for degenerate inputs; payload check is
semantically equivalent.

Audit grep on `lib/segment/src/`:

  $ grep -rn "field_condition_index\|get_match_checkers\|...\|TextQueryType"
  (no matches)

All legacy helper machinery is gone.

Stacked on #8984 (FullTextIndex) → #8983 → #8982 → #8981 → #8980 →

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead (#8986)

* refactor(field_index): migrate indexed_variable_retriever into FieldIndexRead

Follow-up to the condition-checker-migration sub-plan. The read view's
`value_retriever/helpers.rs` previously destructured `FieldIndex`
variants inside `indexed_variable_retriever` to build per-point value
extractors. This PR turns that into a `value_retriever` trait method
on `FieldIndexRead`, so the helper now depends only on the trait —
no variant destructuring outside `FieldIndex`'s own impl.

Changes:

1. FieldIndexRead gains `value_retriever(&self, hw_counter)`. Lives
   on the enum-level trait (rather than `PayloadFieldIndexRead`)
   because the value→Value conversion depends on the payload type
   `U` in `NumericIndex<T, U>`, and only `FieldIndex` knows the
   `(T, U)` pairing.

2. impl FieldIndexRead for FieldIndex implements value_retriever
   with an 11-arm variant match. Bodies copied verbatim from the old
   `indexed_variable_retriever`. FullTextIndex and NullIndex return
   None (caller falls back to payload).

3. read_view/value_retriever/helpers.rs:
   - `variable_retriever` now calls `index.value_retriever(hw_counter)`
     directly via trait dispatch
   - `indexed_variable_retriever` deleted
   - Unused imports dropped (Number, DateTimePayloadType,
     UuidPayloadType, MultiValue)

Helpers.rs shrinks from 189 lines to 73 lines (the test module
stays). Total: +134 / -122 across 3 files, but the structural change
is moving the dispatch into the trait.

Stacked on #8985 (condition-checker-cleanup) → #8984 → … → #8978 → dev.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push value_retriever conversion logic into typed indexes

`FieldIndex::value_retriever` previously inlined the per-variant
value→JSON `Value` conversion (Number, String, DateTime, UUID, Bool,
serde_json::to_value for geo) as a 100-line variant match. Move each
variant's conversion into an inherent `value_retriever` method on the
corresponding typed index; `FieldIndex` is left with a thin
11-arm dispatch that just delegates.

Changes:

1. NumericIndex<T, U> gains 4 per-(T, U) inherent value_retriever
   impls (Int/Datetime/Float/Uuid). The conversion is U-specific
   (timestamp formatting, UUID string, Number::from_f64 etc.), so
   each (T, U) pair has its own impl block.

2. MapIndex<K> gains 3 per-K inherent value_retriever impls
   (Keyword/Int/Uuid).

3. GeoMapIndex and BoolIndex each gain a single inherent
   value_retriever.

4. FieldIndex::value_retriever collapses to a 11-arm match that
   delegates to the typed index's inherent method. FullTextIndex
   and NullIndex still return None at the FieldIndex level — they
   don't expose value retrieval and the caller falls back to payload.

5. field_index.rs sheds the Number, MultiValue and Box::new
   noise — about 100 lines smaller.

Same shape as how `wipe`, `add_point`, `get_telemetry_data` already
delegate from FieldIndex to typed indexes. Adding a new FieldIndex
variant now forces compile errors in (a) the dispatch in FieldIndex
and (b) the new typed index's inherent impl — both correct places.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(field_index): push BoolIndex/NullIndex condition_checker into storage variants

The `BoolIndex` and `NullIndex` wrappers were special-cased among
typed indexes: their `PayloadFieldIndexRead::condition_checker`
impls did the variant-specific work directly on `self` (matching
`Match::Value(Bool)`, `is_empty`, `is_null`) and called
`self.check_values_any` / `self.values_is_empty` / `self.values_is_null`,
each of which dispatched `match self { Mmap(...) | Immutable(...) }`
per point. The inner storage variants (`Immutable/MutableBoolIndex`,
`Immutable/MutableNullIndex`) implemented `PayloadFieldIndexRead`
solely for `filter` / `count_indexed_points` / `estimate_cardinality`
/ `for_each_payload_block` — their `condition_checker` was unreachable
behind the trait's default `None` body.

Removing the trait default surfaced this asymmetry. Rather than stub
the inner-type `condition_checker` as dead `None`, push the real
logic down to where the storage variants live — same shape as
`filter` already uses:

  inner: explicit FieldCondition destructure + exhaustive Match
         arms; per-point closure captures `&'a self` of the inner
         type directly.
  outer: 2-arm `match self { ... => inner.condition_checker(...) }`.

Result: per-point closure body no longer hits a `match self { ... }`
on the wrapper. The wrapper dispatch happens once during setup when
the wrapper picks which inner closure to return. Matches the pattern
the other 5 trait methods (filter/count/estimate/for_each_block) on
these wrappers already use.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

* CI fix

* upd docstring

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

1 participant