Documentation Index
Fetch the complete documentation index at: https://mintlify.com/adelpro/quran-search-engine/llms.txt
Use this file to discover all available pages before exploring further.
Overview
ThegetHighlightRanges() function computes non-overlapping highlight ranges for matched tokens in Arabic text. This is a pure, UI-agnostic function that returns character positions and match types, allowing you to control how highlights are rendered in your application.
Function signature
Parameters
The Arabic text to search for highlights (typically
verse.uthmani or verse.standard)Array of matched tokens from search results (from
verse.matchedTokens). If undefined or empty, returns an empty array.Optional mapping of tokens to their match types (from
verse.tokenTypes). If not provided, all tokens default to 'fuzzy' match type.Return value
Array of non-overlapping highlight ranges, sorted by start position
Starting character index (0-based) in the text
Ending character index (exclusive) in the text
The original query token that matched this range
The type of match:
'exact', 'lemma', 'root', or 'fuzzy'Usage
Basic example
React rendering example
This example shows how to render highlighted text in React without usingdangerouslySetInnerHTML:
How it works
-
Token matching: For each matched token, the function creates a regex pattern that:
- Normalizes Arabic text (handles alef variants, ya/ta marbuta variations)
- Accounts for optional diacritical marks (tashkeel)
- Finds all occurrences in the text
-
Priority sorting: Matches are sorted by:
- Length (longer matches first) to prioritize more specific matches
- Start position (earlier matches first) for stable ordering
-
Overlap resolution: The function ensures non-overlapping ranges by:
- Processing matches in priority order
- Marking occupied character positions
- Skipping matches that overlap with higher-priority matches
- Final ordering: Results are sorted by start position for sequential rendering
Notes
- The function is pure and has no side effects
- Returns an empty array if
matchedTokensisundefinedor empty - Handles Arabic text variations (alef forms, ya/ta marbuta, etc.)
- Ignores diacritical marks when matching
- Guarantees non-overlapping ranges for safe rendering
- Match types default to
'fuzzy'iftokenTypesis not provided