Skip to content

Smith and Schmidt

Edit source

Matching names by how they sound, not how they are spelled.

Part 22 of 38ofFamiliars
  1. 1Session Zero
  2. 2Rolling for a Name
  3. 3The Haunted Handler
  4. 4The Sparse Wheel
  5. 5The Fork in the Path
  6. 6The Planet as a Prefix
  7. 7The Long Division
  8. 8The Line You Usually Cancel
  9. 9Sixteen Bytes Too Far
  10. 10Packing a UUID
  11. 11Bytes You Can Type
  12. 12The Shunting Yard
  13. 13Interchangeable Parts
  14. 14One Loop Per Core
  15. 15The Seam
  16. 16Append Only
  17. 17Who Owns the Tree
  18. 18Down the Flume
  19. 19The Syscalls That Lie
  20. 20Asking the Machine
  21. 21The Earth Is Not a Ball
  22. 22Smith and Schmidt
  23. 23Many Ways to Be Similar
  24. 24Built to Disappear
  25. 25Sometimes a Mutex Is Right
  26. 26Work, Not Threads
  27. 27Before the Program Runs
  28. 28No Collisions, Ever
  29. 29The Names Enums Throw Away
  30. 30The Bag of Holding
  31. 31A Map of Blocks
  32. 32Certainly Absent
  33. 33A Tree Made of Types
  34. 34Everything but the Views
  35. 35Who Owns the Wheel
  36. 36A Guest on the Loop
  37. 37Acknowledged Means Durable
  38. 38Sorted as Bytes

Part of Familiars: the small, sharp libraries I carved out of Xapiand. This one matches by sound: double-metaphone.

Smith and Schmidt are the same name, spelled two ways. If you index people by the spelling of their names, as any literal text index does, those two will never find each other, and neither will Catherine and Kathryn, or Jon and John. That is fine until the thing you are searching is names, at which point it is a disaster, because names are the most spelling-unstable words there are: transliterated, anglicized, typo’d, and written a dozen ways for one sound. The fix is to stop matching letters and start matching sound.

double-metaphone is that: a standalone C++20 implementation of Lawrence Philips’ Double Metaphone, the 2000 successor to his Metaphone, itself a replacement for Soundex. Where Soundex looks only at the surface letters (keep the first, map the rest to a few digit classes, and hope), Double Metaphone reads a word the way it is pronounced. It knows about silent letters, the many ways English writes one sound, and common non-English spellings, so it turns a word into a short key from a tiny sound alphabet, A F H J K L M N P R S T X plus 0 for the “th” sound, where words that sound alike land on the same key even when their spellings differ.

The name is “Double” for the sharpest idea in it: it emits two keys per word, not one.

  • The primary key captures the dominant English pronunciation.
  • The alternate key captures a plausible foreign reading, often Slavic, Germanic, or Romance. When a word has only one likely pronunciation, the alternate just equals the primary.

That second key is exactly what catches names that crossed a language on their way to you. Smith encodes as SM0 and XMT; Schmidt encodes as XMT and SMT. Their primaries differ, but they meet on XMT, because Double Metaphone knows that the German Sch and the English Sm can both reach that sound. A single-key scheme like Soundex has no room to represent “this could be pronounced two ways.” Classic Soundex does file these two together (both S530), but only because it keeps so little of the sound, and it keeps the first letter as written, so Catherine (C365) and Kathryn (K365) never meet; Double Metaphone gives both K0RN. Two keys give a word a chance to match through either of its plausible pronunciations, and that is the whole reason it works on real, messy, multilingual name data where Soundex quietly fails.

Reach for it whenever you match human names or words by how they sound: people search, deduplicating records that were typed by different hands, fuzzy lookups that should survive transliteration. Index a word under its metaphone keys and a query encodes the same way, so Schmidt finds Smith for free. Skip it for non-name text where spelling is stable and semantic similarity, not phonetic, is what you want; a phonetic key will happily collide words that merely share their consonants (cat, kit and coat all encode as KT).

The next familiar zooms out from one comparison to a whole toolbox of them. Sounding alike is only one way two strings can be close, and there is no single right answer to how close, so it offers a family of them behind one interface.