Skip to main content
The Quran Search Engine uses a weighted scoring system to rank search results by relevance. Each match type receives a different point value based on its precision.

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

The computeScore() function evaluates each verse against the search query:

Scoring process

For each token in the query:

1. Check for exact matches (weight: 3)

What happens:
  • Search for the token in the verse text
  • Add 3 points for each occurrence
  • Upgrade matchType to 'exact' if this is the first match
  • Track matched tokens for highlighting

2. Check for lemma matches (weight: 2)

What happens:
  • 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 matchType to 'lemma' only if no exact matches exist

3. Check for root matches (weight: 1)

What happens:
  • 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 matchType to 'root' only if no exact or lemma matches exist

4. Fuzzy matches as fallback (weight: 0.5)

What happens:
  • 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 matchType to '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

The matchType field represents the best match quality for a verse:
Priority order:
  1. exact – Direct text match
  2. lemma – Morphological form match
  3. root – Linguistic root match
  4. fuzzy – Approximate match
  5. none – 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)
Higher scores appear first in search results. A verse with score: 9 ranks above one with score: 4.

Final output

Each result includes complete scoring metadata:
Example result:

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 matchedTokens and tokenTypes
  • 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.