Skip to main content

Overview

All types are exported from quran-search-engine and provide full TypeScript support for search operations, highlighting, and data structures.

Core types

QuranText

Represents a single verse in the Quran dataset. This is the input type for search operations.
number
Unique global verse identifier (1-6236)
number
Chapter number (1-114)
number
Verse number within the chapter
string
Formatted verse identifier for display (e.g., “1:1”)
string
Verse text in Uthmani script with diacritics (commonly used for display and highlighting)
string
Verse text in standard Arabic script (used for exact text matching)
string
Full verse text including Bismillah where applicable
number
Page number in the Mushaf
number
Juz (part) number (1-30)
string
Chapter name in Arabic
string
Chapter name in English
string
Romanized chapter name

ScoredQuranText

Extends QuranText with search scoring and highlighting metadata. This is the type returned in search results.
number
Total score for this verse based on match quality:
  • Exact matches: +3 per token
  • Lemma matches: +2 per token
  • Root matches: +1 per token
  • Fuzzy matches: +0.5 per token
MatchType
The best overall match type for this verse: 'exact', 'lemma', 'root', 'fuzzy', or 'none'
string[]
Deduplicated array of query tokens that matched in this verse (used for highlighting)
Record<string, MatchType>
Optional mapping of each matched token to its match type (used for match-type-specific highlighting)

SearchResponse

The complete response object returned by the search() function.
ScoredQuranText[]
Array of matching verses, sorted by match score (highest first)
SearchCounts
Match statistics by type
number
Number of exact text matches
number
Number of lemma matches
number
Number of root matches
number
Number of fuzzy matches
number
Total number of matches across all types
object
Pagination metadata
number
Total number of matching verses
number
Total number of pages based on limit
number
Current page number (1-based)
number
Number of results per page

SearchOptions

Configuration options for search behavior.
boolean
required
Enable lemma-based matching (requires morphology data and word map)
boolean
required
Enable root-based matching (requires morphology data and word map)
boolean
Enable fuzzy fallback matching. Defaults to true. Set to false to disable fuzzy search entirely.

SearchCounts

Match statistics returned by the search function, providing breakdown of results by match type.
number
Number of verses with exact text matches
number
Number of verses with lemma-based matches
number
Number of verses with root-based matches
number
Number of verses with only fuzzy matches
number
Total number of matching verses across all types

Morphology types

MorphologyAya

Morphological data for a single verse, containing lemmas and roots for linguistic matching.
number
Global verse identifier matching QuranText.gid
string[]
Array of normalized lemma forms for all words in the verse
string[]
Array of Arabic roots for all words in the verse

WordMap

Dictionary mapping normalized query tokens to their canonical lemma and root forms.
object
Normalized token as key
string
Canonical lemma form of the token
string
Arabic root of the token
Example:

Match types

MatchType

Enumeration of possible match types for search results.
literal
Direct text match in the verse (highest priority, score: +3)
literal
Lemma-based match using morphological analysis (score: +2)
literal
Root-based match using Arabic roots (score: +1)
literal
Fuzzy match fallback when no exact/lemma/root match found (score: +0.5)
literal
No match (used internally)

HighlightRange

Represents a character range to highlight in the text, returned by getHighlightRanges().
number
Starting character index (0-based, inclusive)
number
Ending character index (0-based, exclusive)
string
The original query token that matched this range
MatchType
The type of match for this range

Pagination types

PaginationOptions

Options for paginating search results.
number
Page number to retrieve (1-based). Defaults to 1.
number
Number of results per page. Defaults to 10.
Example:

Custom dataset types

VerseInput

Minimal interface required for custom verse datasets.
number
required
Unique verse identifier (used to join with morphology data)
string
required
Verse text with diacritics (used for fuzzy fallback and highlighting)
string
required
Verse text in standard form (used for exact text matching)
Custom dataset example: