This feature adds the ability to search the Quran using English words (and their synonyms), which are translated to Arabic roots for searching. The implementation leverages the library’s existing root search capability.
interface EnglishArabicConcept {
english: string[]; // All English variants (synonyms) in one field
arabic: string[]; // Arabic roots only - library handles the rest
}
{
"english": ["truth", "verity", "trueness", "accuracy"],
"arabic": ["حق", "صدق"]
}
arabic field; the library’s built-in root search automatically finds all derived wordsUser Query: "truth verity"
↓
Split into tokens: ["truth", "verity"]
↓
For each token:
↓
┌─────────────────────────────────────┐
│ isArabic(token)? │
├──────────────┬──────────────────────┤
│ YES │ NO │
│ ↓ │ ↓ │
│ Pass │ 1. English→Arabic │
│ through │ (NEW) │
│ unchanged │ 2. Phonetic │
│ │ (existing) │
└──────────────┴──────────────────────┘
↓
If English found in translation map:
"truth" → ["حق", "صدق"]
"verity" → ["حق", "صدق"]
↓
Dedupe and combine: ["حق", "صدق"]
↓
Run search with root:true enabled
Library automatically finds:
- "الحق", "بالحق", "حقا" (from root "حق")
- "صدق", "صدقا", "بالصدق" (from root "صدق")
The English→Arabic translation is integrated at search.ts#L158, right before the existing phonetic lookup:
if (!isArabic(token)) {
const cleanToken = token.toLowerCase().trim();
// 1. English → Arabic translation (NEW)
let arabicRoots = englishArabicMap.get(cleanToken);
if (arabicRoots) {
return arabicRoots[0]; // Use roots, library handles rest
}
// 2. Phonetic fallback (EXISTING)
let arabicPossibilities = phoneticMap.get(cleanToken);
// ...
}
The English translation lookup only runs when the query is NOT Arabic:
if (token && !isArabic(token)) {
// Translation or Phonetic lookup happens here
}
This means:
import { search } from 'quran-search-engine';
// Search using English word
const result = search('truth', quranData, morphologyMap, wordMap, {
lemma: true,
root: true, // Important: enables root-based search
semantic: true,
});
// The library will:
// 1. Look up "truth" in English→Arabic map
// 2. Find roots ["حق", "صدق"]
// 3. Search for all words derived from these roots
// 4. Return matching verses
| Feature | Phonetic | English Translation |
|---|---|---|
| Input | Latin letters mimicking Arabic pronunciation | English words |
| Example | “bismillah” → “بسم الله” | “truth” → [“حق”, “صدق”] |
| Type | Transliteration (sound-based) | Translation (meaning-based) |
| Data | Pre-computed phonetic mappings | English synonyms → Arabic roots |