#1043·orama

Arabic tokenizer splits words at آ, ء, vowel marks and the Persian letters پ چ ژ ک گ ی

Author: navidkashaniCreated Sep 28, 2026Updated Sep 28, 2026

Describe the bug

The arabic splitter in packages/orama/src/components/tokenizer/languages.ts is

typescript
arabic: /[^a-z0-9أ-ي]+/gim,

أ-ي is U+0623…U+064A. Every Arabic-script character outside that range is treated as a word separator, so it is dropped and the word is cut in two:

  • Arabic letters: آ (U+0622) and ء (U+0621).
  • Vowel marks (harakat, U+064B–U+0652): any vowelled text breaks.
  • Persian letters: پ چ ژ ک گ ی (U+067E, U+0686, U+0698, U+06A9, U+06AF, U+06CC). The same letters are used in Urdu and other languages written in Arabic script.

With the default english language, Arabic script produces no tokens at all.

To reproduce

Orama 3.1.18 (the splitter is unchanged on main):

javascript
import { create, insert, search } from "@orama/orama";

const db = create({ schema: { title: "string" }, language: "arabic" });
for (const w of ["آخر", "ماء", "كِتَابٌ", "القرآن", "گوشی", "کتاب"]) {
  console.log(w, db.tokenizer.tokenize(w, "arabic"));
}
// آخر    [ 'خر' ]
// ماء    [ 'ما' ]
// كِتَابٌ  [ 'ك', 'ت', 'اب' ]
// القرآن [ 'القر', 'ن' ]
// گوشی   [ 'وش' ]    (Persian "phone")
// کتاب   [ 'تاب' ]   (Persian "book")

for (const title of ["کتاب کودک", "تاب بازی", "گوشی سامسونگ", "گوش درد"]) await insert(db, { title });
(await search(db, { term: "کتاب" })).hits.map((h) => h.document.title); // [ 'کتاب کودک', 'تاب بازی' ]  (book → also "swing")
(await search(db, { term: "گوشی" })).hits.map((h) => h.document.title); // [ 'گوشی سامسونگ', 'گوش درد' ] (phone → also "earache")

Expected behavior

Letters and marks of the Arabic block are kept inside the word: آخر, ماء, كتاب, القرآن, گوشی and کتاب each come out as one token.

Impact

In a benchmark of 60,000 Persian pages (20,000 each of Wikipedia, news and product titles), searching a page's own title words, exactly as written, found that page in 0% of queries on Wikipedia and news with the default language (12% on products, through Latin model names). With language: "arabic" and tolerance: 1 it was 25–34%. With a tokenizer that keeps whole Persian words (and folds Arabic ي/ك to Persian ی/ک) it was 100%.

Suggested fix

Split on anything that is not a letter, digit or mark, in any script (this also keeps Arabic punctuation such as ، ؛ ؟ out of tokens):

typescript
arabic: /[^\p{L}\p{N}\p{M}]+/gu,

and let normalizeToken drop the vowel marks (U+064B–U+065F, U+0670) and tatweel (U+0640), so كِتَابٌ and كتاب meet.

A separate persian language would also help. It would use the same splitter, fold ي→ی and ك→ک, and add the Snowball Persian stemmer (Snowball 3.1.0+, BSD-3) to @orama/stemmers the way #124 added the others.

I'm happy to send a PR for the splitter fix, and for persian if you'd like it.