Score weights
The scoring system assigns points based on match quality:Scores accumulate for each matched token in a verse. A verse matching multiple tokens will have a higher total score.
How scoring works
ThecomputeScore() function evaluates each verse against the search query:
Scoring process
For each token in the query:1. Check for exact matches (weight: 3)
- Search for the token in the verse text
- Add 3 points for each occurrence
- Upgrade
matchTypeto'exact'if this is the first match - Track matched tokens for highlighting
2. Check for lemma matches (weight: 2)
- Look up the token’s lemma in the word map
- Search for that lemma in the verse’s morphology
- Add 2 points for each lemma match
- Set
matchTypeto'lemma'only if no exact matches exist
3. Check for root matches (weight: 1)
- Look up the token’s root in the word map
- Search for that root in the verse’s morphology
- Add 1 point for each root match
- Set
matchTypeto'root'only if no exact or lemma matches exist
4. Fuzzy matches as fallback (weight: 0.5)
- Only applied if no exact, lemma, or root matches were found
- Extract matched tokens from Fuse.js match indices
- Add 0.5 points for each fuzzy token
- Set
matchTypeto'fuzzy'
Fuzzy matches only contribute to scoring when they’re the only type of match found. They serve as a fallback layer.
Match type hierarchy
ThematchType field represents the best match quality for a verse:
exact– Direct text matchlemma– Morphological form matchroot– Linguistic root matchfuzzy– Approximate matchnone– No match
Scoring examples
Example 1: Single exact match
Query:اللهVerse: Contains
الله once in the text
Example 2: Multiple exact matches
Query:الله الرحمنVerse: Contains both
الله (2 times) and الرحمن (1 time)
Example 3: Mixed match types
Query:الله الرحمنVerse: Contains
الله exactly (1 time) and a lemma match for الرحمن (1 time)
Example 4: Lemma-only match
Query:صلىVerse: Contains different forms of the lemma
صلى (e.g., يصلون, صلاة) 2 times
Example 5: Fuzzy fallback
Query:الرحمان (typo)Verse: Contains
الرحمن (fuzzy match)
Final output
Each result includes complete scoring metadata:Using scores in your UI
You can use the scoring data to:- Sort results by relevance (done automatically)
- Display match quality badges (exact, lemma, root, fuzzy)
- Highlight matched text using
matchedTokensandtokenTypes - Filter by match type (e.g., show only exact matches)
- Show score values for debugging or transparency
The search response also includes aggregate counts by match type in the
counts field.