Skip to main content

Signature

Description

Performs a comprehensive search across the Quran that combines simple text search with linguistic (lemma/root) analysis and fuzzy fallback. Results are scored, deduplicated, and sorted by relevance. This is your primary API for Quran search results with scoring and pagination.

Parameters

string
required
The search query in Arabic text. Non-Arabic characters are automatically stripped during processing.
TVerse[]
required
Array of Quran verses to search. Each verse must satisfy the VerseInput type with gid, uthmani, and standard fields.
Map<number, MorphologyAya>
required
Map of verse morphology data indexed by gid. Each entry contains lemmas and roots arrays for linguistic matching.
WordMap
required
Dictionary mapping normalized query tokens to their canonical lemma and root forms.
AdvancedSearchOptions
default:"{ lemma: true, root: true }"
Search options controlling linguistic matching:
  • lemma (boolean): Enable lemma-based matching
  • root (boolean): Enable root-based matching
  • fuzzy (boolean, optional): Enable fuzzy fallback matching (default: true)
Set fuzzy: false to disable fuzzy fallback when no exact/lemma/root matches are found.
PaginationOptions
default:"{ page: 1, limit: 20 }"
Pagination controls:
  • page (number, optional): Page number to retrieve (default: 1)
  • limit (number, optional): Results per page (default: 20)

Returns

object
ScoredVerse[]
Array of matching verses with scoring metadata. Each result includes:
  • All original verse fields
  • matchScore (number): Weighted relevance score
  • matchType (MatchType): Best match type (‘exact’ | ‘lemma’ | ‘root’ | ‘fuzzy’ | ‘none’)
  • matchedTokens (string[]): Deduplicated matched tokens for highlighting
  • tokenTypes (Record<string, MatchType>): Match type for each token
SearchCounts
Match type breakdown:
  • simple (number): Verses with exact text matches
  • lemma (number): Verses with lemma matches
  • root (number): Verses with root matches
  • fuzzy (number): Verses with only fuzzy matches
  • total (number): Total matching verses
object
Pagination metadata:
  • totalResults (number): Total matching verses across all pages
  • totalPages (number): Total number of pages
  • currentPage (number): Current page number
  • limit (number): Results per page

Scoring system

Match types are weighted differently:

Multi-word queries

The search uses AND logic:
  • Query is split by whitespace into tokens
  • Results must match every token (via exact, lemma/root, or fuzzy fallback)
  • Scores accumulate across all matched tokens

Examples

With pagination

Disable fuzzy matching

Custom dataset

Notes

  • The query is automatically normalized (Arabic normalization, tashkeel removal)
  • Non-Arabic characters are stripped from the query
  • Empty queries return an empty result set
  • Results are sorted by matchScore in descending order
  • Use matchedTokens with getHighlightRanges() for UI highlighting