Skip to main content

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

Lazily loads the Word Map data. This large dataset is loaded asynchronously to avoid increasing the initial bundle size. The word map enables mapping normalized query tokens to their canonical lemma and root forms.

Signature

export const loadWordMap = async (): Promise<WordMap>

Return value

Promise<WordMap>
Promise
A Promise that resolves to the WordMap object. This is a dictionary mapping normalized Arabic words to their lemma and root information.

WordMap structure

The WordMap is an object with normalized tokens as keys:
type WordMap = {
  [key: string]: {
    lemma?: string;
    root?: string;
  };
};
[normalizedToken]
object
Each key is a normalized Arabic word/token from the Quran
[normalizedToken].lemma
string
The canonical lemma (dictionary form) of the word
[normalizedToken].root
string
The root letters of the word (typically 3-4 letters separated by spaces)

Example

import { loadWordMap, type WordMap } from 'quran-search-engine';

const wordMap: WordMap = await loadWordMap();

// Look up a specific word
console.log(wordMap['الله']);
// => { lemma: 'الله', root: 'ا ل ه' }

console.log(wordMap['الرحمن']);
// => { lemma: 'الرحمن', root: 'ر ح م' }

// Total unique words in the map
console.log(Object.keys(wordMap).length);
// => (varies by dataset version)
The word map is used to resolve query tokens into lemmas and roots:
import {
  search,
  loadQuranData,
  loadMorphology,
  loadWordMap,
} from 'quran-search-engine';

const [quranData, morphologyMap, wordMap] = await Promise.all([
  loadQuranData(),
  loadMorphology(),
  loadWordMap(),
]);

// When you search for 'الله الرحمن', the search function:
// 1. Normalizes the query tokens
// 2. Looks up each token in wordMap to find its lemma/root
// 3. Uses those forms to match against verse morphology data

const response = search('الله الرحمن', quranData, morphologyMap, wordMap, {
  lemma: true,  // Uses wordMap to resolve query lemmas
  root: true,   // Uses wordMap to resolve query roots
});

How it works

The word map enables advanced morphological matching:
// User searches for a word
const query = 'الله';

// 1. Query is normalized
// 2. Lookup in wordMap
const mapping = wordMap['الله'];
// => { lemma: 'الله', root: 'ا ل ه' }

// 3. Search can now match:
//    - Exact: 'الله'
//    - Lemma: any word with lemma 'الله'
//    - Root: any word with root 'ا ل ه'

Data source

The word mapping data comes from Quranic Arabic Corpus v4.0: https://corpus.quran.com

Error handling

Throws an error if the word map data file cannot be loaded:
try {
  const wordMap = await loadWordMap();
} catch (error) {
  console.error('Failed to load word map:', error);
  // Error: Could not load word map data. Ensure src/data/word-map.json exists.
}

Without word map

You can use the search function without a word map (lemma/root matching disabled):
import { search, loadQuranData } from 'quran-search-engine';

const quranData = await loadQuranData();

// Use empty object if word map not needed
const response = search('الله', quranData, new Map(), {}, {
  lemma: false,
  root: false,
});
// Only exact text matching will be performed

Performance consideration

The word map is loaded once at application startup and reused across all searches. This provides fast O(1) lookups during query resolution without repeated file reads.

Build docs developers (and LLMs) love