Why is this an issue?
The extract_highlight() function at cloudsearch-index/src/lib.rs:1831-1835 uses hardcoded magic numbers for context window sizing without named constants:
let pre_start = pos.saturating_sub(50);
let post_end = pos.saturating_add(term.len() + 30).min(text.len());
A reader cannot tell what 50 and 30 represent or why those values were chosen. The values are not documented, not configurable, and appear in multiple places.
What is causing it?
Constants were inlined directly in the code rather than extracted to named constants.
How can it be solved?
Extract to module-level constants:
const HIGHLIGHT_PRE_CONTEXT_CHARS: usize = 50;
const HIGHLIGHT_POST_CONTEXT_CHARS: usize = 30;
Also consider making these configurable via IndexSettings if users might want different highlight window sizes.
Category
Severity
Why is this an issue?
The
extract_highlight()function atcloudsearch-index/src/lib.rs:1831-1835uses hardcoded magic numbers for context window sizing without named constants:A reader cannot tell what
50and30represent or why those values were chosen. The values are not documented, not configurable, and appear in multiple places.What is causing it?
Constants were inlined directly in the code rather than extracted to named constants.
How can it be solved?
Extract to module-level constants:
Also consider making these configurable via
IndexSettingsif users might want different highlight window sizes.Category
Severity