- Private CRM: an AI CRM where Claude does the data entry and you make the calls · part 7 of 12
- Rust
- React
- CRM
- RTL
Arabic-aware search, tags and CSV import in a CRM built in Rust
How Private CRM finds أحمد when you type احمد, keeps tags tidy, and imports contacts from messy CSV files with English or Arabic headers on a queue.
5 min read
Type أحمد into most search boxes and you won't find the contact saved as احمد. Same name, different first letter: one has a hamza, one doesn't. In a CRM used in Kuwait that matters, and the same thing happens with any name ending in taa marbuta, like Fatima.
This post covers three ways contacts get into Private CRM and get found again: tags, a sidebar search that understands Arabic spellings, and CSV import.
Tags: a JSON list with rules
Each contact, company or deal has tags, stored as a JSON list on the record. No tags table, no join. The rules live in code:
- trimmed, so "vip " and "vip" are one tag
- deduplicated ignoring case
- at most 10 per record, up to 32 characters each
Forms suggest tags already in use, lists show them as badges, and every filter drawer can filter by tag. Over MCP, list_tags returns the tags in use so an agent reuses "vip" instead of inventing "VIP-client". Going over 10 is refused with an error, not silently trimmed. An agent that thinks it saved 12 tags should hear that it didn't.
Arabic-aware search
The sidebar search (Cmd+K or Ctrl+K) finds contacts, companies or deals in one box. The trick is a search_text column on each of those tables, holding a folded copy of the name or title. Model hooks fill it on every save, and a migration backfilled existing rows.
The folding is one function:
pub fn normalize(text: &str) -> String {
let folded: String = text
.chars()
.filter(|c| !matches!(c, '\u{064B}'..='\u{065F}' | '\u{0670}' | '\u{0640}'))
.map(|c| match c {
'أ' | 'إ' | 'آ' | 'ٱ' => 'ا',
'ة' => 'ه',
'ى' | 'ئ' => 'ي',
'ؤ' => 'و',
'٠'..='٩' => char::from(b'0' + (c as u32 - '٠' as u32) as u8),
_ => c,
})
.flat_map(char::to_lowercase)
.collect();
folded.split_whitespace().collect::<Vec<_>>().join(" ")
}
The filter drops diacritics (harakat) and tatweel, the stretching character people use for style. The map merges the alef forms, turns taa marbuta into haa, merges alef maqsura and yaa, and converts Arabic-Indic digits to 0-9. Then it lowercases and collapses spaces, which handles English names too.
The tests are the clearest spec:
assert_eq!(normalize("أحمد"), normalize("احمد"));
assert_eq!(normalize("فاطمة"), "فاطمه");
assert_eq!(normalize("مُحَمَّد"), "محمد");
assert_eq!(normalize("عـــلي"), "علي");
assert_eq!(normalize("٢٠٢٦"), "2026");
Because the folding happens in Rust and the column is plain text, the query is an ordinary match that behaves the same on SQLite and PostgreSQL. The list pages and the MCP search_contacts tool use the same column. GET /search returns up to five matches of each kind, scoped to what the user can see.
Putting it on shadcn's Command
The first search box had its own key handling. A later commit rebuilt it on the shadcn Command component, which wraps cmdk. Arrow keys and Enter now come from cmdk, and every part of the box follows the theme.
One setting mattered: cmdk's own filter is off. cmdk would filter the server's results again in the browser, with no idea that أحمد and احمد are the same. The server already did the matching, so the client just shows what it got.
CSV import
Most contacts arrive in bulk from a spreadsheet. The import flow:
- Upload a CSV, up to 5 MB, UTF-8 with or without a BOM, separated by commas, semicolons or tabs. Excel in Arabic locales loves semicolons.
- The upload creates a
contact_importsrow and opens a page to match columns. Matches are guessed from English or Arabic headers, and you can change them. A preview shows the first rows. - Confirming queues an
ImportContactsjob. The page polls for progress. - The job validates each row like the contact form, creates companies by name, and skips or updates contacts whose email already exists, your choice.
- Failed rows are recorded with a reason and download as a CSV with the original headers. Fix them, upload again.
- The uploaded file is deleted when the import ends.
Running it on the queue keeps a 5 MB upload from holding a web request open. It also means a queue worker has to be running, which is why npm run dev starts one alongside the server and Vite, and why the Docker setup in part 11 has a worker container.
Keeping the original headers on the failed-rows file was a small decision with a big effect. People fix the file in the same spreadsheet they exported from, and the column matching guesses right on the second upload.
Duplicates on the way in
The same "already exists" rule from the MCP tools applies here and in the form. A second contact with an existing email is refused, and the form links to the first one. Over MCP, create_contact returns the existing contact with created: false. Three entry points, one rule.
Try this on your own data
If your users write Arabic, add a folded search column today. It's one function and one migration, and it fixes a whole class of "I know they're in here" complaints. Do the folding in app code so it works on any database. For more on the SQL side of fast searches, see how to optimize SQL queries.
Part 8 goes further into Arabic: translating every screen and flipping the layout right to left.
Last updated 4 Dec 2026 · filed under Rust, react, crm, rtl