Showing a Snippet Around a Search Hit
A snippet can give nearby readable context for a match while keeping the full document available through its detail link.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a matched sentence
A query for remainder may match near a division example. A snippet can include that line and enough surrounding words to explain it. String slice bounds support a controlled excerpt.
Mark and render the source safely
Use term offsets appropriate to the original text and handle punctuation as data. Keep the link's destination visible. See text rendering boundaries.[1]
Reconcile indexed positions with original display text
A document contains “Café guide to maps.” An index might normalize the accented word before matching, while the snippet should display the original text. Track ranges in the source representation or map normalized ranges back to it. See Unicode positions.
Match token maps
Display window includes surrounding words
Highlight source spans using original text offsets
Keep existing spelling visible
Test the beginning and end of the source
A window can be clipped to available characters. Keep output safe as text and avoid splitting user-visible text units unnecessarily. Test two occurrences and a result with no match in the displayable field.