Text & Digit Normalization Engine â
In regional e-commerce, inconsistency in user input (such as mixed Arabic/Persian keyboards, non-standard Persian numerals, and inconsistent zero-width non-joiners) frequently breaks search indexes and phone number validations.
Reyhan Commerce includes a dedicated Text Normalization Engine that automatically cleans incoming requests before they reach validation rules or database queries.
1. Normalization Pipeline Rules â
text
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Incoming Raw Request Payload â
ââââââââââââââââââââââââââââââââŹâââââââââââââââââââââââââââââââ
â
âź
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Reyhan Normalization Middleware â
â 1. Digit Conversion: '۰۹۲۳۴۾ۜۡ۸ۚ' âââś '0123456789' â
â 2. Character Fixes: 'Ů', 'Ů', 'ŘŠ' âââś 'Ű', 'ÚŠ', 'Ů' â
â 3. ZWNJ Standardizer: Standardizes half-spaces in titles â
â 4. Whitespace Trimming: Removes invisible unicode spaces â
ââââââââââââââââââââââââââââââââŹâââââââââââââââââââââââââââââââ
â
âź
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Validated DTO & Search Index Queries â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ2. Using the Normalizer Programmatically â
You can invoke the normalization service directly anywhere in your custom actions or extensions:
php
use Reyhan\Core\Services\Normalization\PersianNormalizer;
$cleanedMobile = PersianNormalizer::toAsciiDigits('۰ۚ۹۲۳۴۾ۜۡ۸ۚ');
// Output: '09123456789'
$cleanedTitle = PersianNormalizer::clean('ŮŘąŮ
Ů
عءŮب ŮŮŮŘŻŮ ŮžŮست');
// Output: 'ÚŠŘąŮ
Ů
عءŮب ÚŠŮŮŘŻŮ ŮžŮست'3. Database Search Integration â
By combining normalized text inputs with PostgreSQL's pg_trgm extension and GIN indices, store searches achieve typo tolerance and instant match scoring across product titles and descriptions.