Skip to content

extract_highlight: magic numbers 50 and 30 not extracted to named constants #86

@poyrazK

Description

@poyrazK

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

  • Small
  • Medium
  • Large

Severity

  • Low
  • Medium
  • High
  • Critical

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions