Abdulkader Safi

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

Share
CRM search box matching Arabic names typed with different spellings of alef and taa marbuta

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.

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:

  1. 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.
  2. The upload creates a contact_imports row 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.
  3. Confirming queues an ImportContacts job. The page polls for progress.
  4. The job validates each row like the contact form, creates companies by name, and skips or updates contacts whose email already exists, your choice.
  5. Failed rows are recorded with a reason and download as a CSV with the original headers. Fix them, upload again.
  6. 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

Every entry on this project

12 build notes, in order

Including the ones where nothing worked. You are on part 7.

Read the series →

FAQ

Frequently asked questions

Why doesn't searching أحمد find احمد?

They are different characters: أ is alef with hamza and ا is plain alef. People type both for the same name. Private CRM folds أ إ آ ٱ to ا, ة to ه, ى and ئ to ي, ؤ to و, drops diacritics and tatweel, and compares the folded forms, so either spelling finds the other.

Should Arabic search normalization happen in SQL or in the app?

Private CRM does it in the app and stores the result. Contacts, companies and deals keep a normalized copy of their name in a search_text column, filled by model hooks on every save and backfilled by a migration. The search term gets the same folding, then a plain LIKE match works on SQLite and PostgreSQL alike.

How do you import a CSV that might be semicolon separated or have a BOM?

Private CRM accepts UTF-8 files up to 5 MB, with or without a byte order mark, separated by commas, semicolons or tabs. After upload it shows a page to match columns, guessed from English or Arabic headers, with a preview of the first rows before anything is imported.

What should happen to CSV rows that fail validation?

They should be kept with a reason, not dropped. Private CRM validates each row like the contact form, records failed rows with the reason, and lets you download them as a CSV with the original headers so you can fix and upload them again.

Written by

Abdulkader Safi

Software Engineer

Lead engineer at DSRPT, from Lebanon and based in Kuwait. I write about the tools and bugs from real client work, with the numbers I measured.

About me → GitHub LinkedIn

Need this kind of work done on your project?

Start a project →

Keep reading

More from Private CRM: an AI CRM where Claude does the data entry and you make the calls

All 12 entries →