Expand description
Search-result highlighting.
Highlighting operates in two phases:
- Build a set of analyzed query terms (lower-cased + stemmed +
char/token filtered through the same
Analyzerpipeline used for indexing). When the caller does not supply an analyzer, the fallback is a plain ASCII lower-case fold so the highlighter still works as a stand-alone helper. - Walk the source text with a
\w+tokenizer; every token whose analyzed form intersects the query-term set becomes a highlight span. Spans are wrapped with the configuredstart_tag/end_tag, or projected into a fragment view whenmax_fragments > 0.
The matcher operates on character offsets rather than byte offsets, so highlight spans align correctly in CJK and other multibyte text.
use uqa_analysis::{highlight, HighlightOptions};
let out = highlight(
"the quick brown fox jumps over the lazy dog",
&["fox".into(), "dog".into()],
None,
&HighlightOptions::default(),
).unwrap();
assert!(out.contains("<b>fox</b>"));
assert!(out.contains("<b>dog</b>"));Structs§
- Highlight
Options - Per-call configuration. Defaults use
<b>/</b>tags, a full-text highlight with no fragment cap, and 150-char fragments whenmax_fragments > 0.
Functions§
- highlight
- Wrap matched query terms in
textwith the configured tags.