Repository navigation
refactor: introduce FieldIndexRead trait - #8975
Conversation
Mirror the PayloadFieldIndex / PayloadFieldIndexRead split (#8966) one layer up at the FieldIndex enum level. FieldIndexRead names the uniform read-only surface (filter, estimate_cardinality, count_indexed_points, for_each_payload_block, get_telemetry_data, values_count, values_is_empty, special_check_condition, as_numeric, as_facet_index) — the methods that StructPayloadIndexReadView and its helpers reach through IndexesMap. Trait declaration only. No impl, no callers in this PR — this is purely additive. Follow-up PRs will impl it on FieldIndex, then migrate non-destructuring helpers to a FieldIndexRead bound. as_numeric and as_facet_index use return-position impl Trait (impl NumericFieldIndexRead + '_, impl FacetIndex + '_), matching how PayloadIndexRead exposes the same shapes. The trait is therefore not object-safe; consumers will use a generic bound rather than &dyn FieldIndexRead. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR introduces a new read-only trait Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The helpers in query_optimization/condition_converter{,/match_converter}.rs
and the bulk of query_optimization/rescore_formula/value_retriever.rs were
only ever called from struct_payload_index/read_view/. Move them next to
their callers.
The trait split work (#8975, #8976) showed why these helpers can't migrate
to a uniform FieldIndexRead bound: every branch in field_condition_index,
match_converter, get_range_*, get_geo_*, indexed_variable_retriever
destructures FieldIndex variants and reaches into variant-specific
predicates on the underlying typed indexes (MapIndex::check_values_any,
FullTextIndex::parse_*_query, NumericIndex::get_values, …). The variant
match is the whole point of these helpers; co-locating them with the read
view is the right shape.
New layout:
- read_view/condition_converter/{mod.rs, helpers.rs, match_converter.rs}
(was a flat read_view/condition_converter.rs + scattered query_optimization
files)
- read_view/value_retriever/{mod.rs, helpers.rs}
(was a flat read_view/value_retriever.rs + query_optimization/rescore_formula/
value_retriever.rs)
VariableRetrieverFn type alias stays in query_optimization/rescore_formula/
value_retriever.rs (now a 6-line file): formula_scorer.rs in the same module
uses it as a struct field, so the type belongs there. Only the helper
functions and their tests move.
Visibility tightened where natural: cross-file entry points are
pub(super), purely-local helpers are private, public-API surface is
unchanged.
No behavioural change. cargo test -p segment: 666 unit + 120 integration
tests pass.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Mirror the PayloadFieldIndex / PayloadFieldIndexRead split (#8966) one layer up at the FieldIndex enum level. FieldIndexRead names the uniform read-only surface (filter, estimate_cardinality, count_indexed_points, for_each_payload_block, get_telemetry_data, values_count, values_is_empty, special_check_condition, as_numeric, as_facet_index) — the methods that StructPayloadIndexReadView and its helpers reach through IndexesMap. Trait declaration only. No impl, no callers in this PR — this is purely additive. Follow-up PRs will impl it on FieldIndex, then migrate non-destructuring helpers to a FieldIndexRead bound. as_numeric and as_facet_index use return-position impl Trait (impl NumericFieldIndexRead + '_, impl FacetIndex + '_), matching how PayloadIndexRead exposes the same shapes. The trait is therefore not object-safe; consumers will use a generic bound rather than &dyn FieldIndexRead. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
The helpers in query_optimization/condition_converter{,/match_converter}.rs
and the bulk of query_optimization/rescore_formula/value_retriever.rs were
only ever called from struct_payload_index/read_view/. Move them next to
their callers.
The trait split work (#8975, #8976) showed why these helpers can't migrate
to a uniform FieldIndexRead bound: every branch in field_condition_index,
match_converter, get_range_*, get_geo_*, indexed_variable_retriever
destructures FieldIndex variants and reaches into variant-specific
predicates on the underlying typed indexes (MapIndex::check_values_any,
FullTextIndex::parse_*_query, NumericIndex::get_values, …). The variant
match is the whole point of these helpers; co-locating them with the read
view is the right shape.
New layout:
- read_view/condition_converter/{mod.rs, helpers.rs, match_converter.rs}
(was a flat read_view/condition_converter.rs + scattered query_optimization
files)
- read_view/value_retriever/{mod.rs, helpers.rs}
(was a flat read_view/value_retriever.rs + query_optimization/rescore_formula/
value_retriever.rs)
VariableRetrieverFn type alias stays in query_optimization/rescore_formula/
value_retriever.rs (now a 6-line file): formula_scorer.rs in the same module
uses it as a struct field, so the type belongs there. Only the helper
functions and their tests move.
Visibility tightened where natural: cross-file entry points are
pub(super), purely-local helpers are private, public-API surface is
unchanged.
No behavioural change. cargo test -p segment: 666 unit + 120 integration
tests pass.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Mirror the
PayloadFieldIndex/PayloadFieldIndexReadsplit (#8966) one layer up at theFieldIndexenum level.FieldIndexReadnames the uniform read-only surface thatStructPayloadIndexReadViewand its helpers reach throughIndexesMap:count_indexed_points,filter,estimate_cardinality,for_each_payload_blockget_telemetry_data,values_count,values_is_empty,special_check_conditionas_numeric,as_facet_indexLifecycle / disk methods (
flusher,files,is_on_disk,populate,clear_cache,ram_usage_bytes,get_full_index_type) and write methods (add_point,remove_point,wipe) stay off the trait — they have no read-side callers.This PR is trait declaration only — no impl, no consumers, purely additive. Two follow-up PRs (already planned) will:
impl FieldIndexRead for FieldIndexand remove the now-duplicated inherent methods so call sites resolve through the trait.get_fallback_is_empty_checkerto aFieldIndexReadbound. Variant-destructuring helpers (field_condition_index,match_converter,get_range_*,get_geo_*,indexed_variable_retriever) keep&FieldIndex— they reach into variant-specific predicates on the underlying typed indexes that aren't on the uniform trait.Why generics on
as_numeric/as_facet_indexBoth methods use return-position
impl Trait(Option<impl NumericFieldIndexRead + '_>/Option<impl FacetIndex + '_>), matching the shapePayloadIndexRead::numeric_index_for/facet_index_foralready use. The concrete numeric/facet types stay opaque per implementation. Consequence:FieldIndexReadis not object-safe; follow-up consumers will use a generic bound (<I: FieldIndexRead + ?Sized>) rather than&dyn FieldIndexRead. Static dispatch, no v-table — same approach asPayloadIndexRead.Test plan
cargo build -p segmentcargo build --workspace🤖 Generated with Claude Code