Metaphone
What it is
Metaphone is a phonetic encoding algorithm published by Lawrence Philips in Computer Language magazine in 1990. It was designed as a direct response to the limitations of Soundex: where Soundex assigns consonants to coarse digit classes with no regard for English pronunciation rules, Metaphone models the actual phonology of English — silent letters, digraphs, and context-sensitive sound shifts.
The output is a variable-length string composed entirely of consonant sounds, drawn from a reduced alphabet. Vowels are discarded entirely, except at the very start of a word if the word begins with a vowel. There is no fixed-width padding or truncation; the code is as long as the phonetic content of the word requires.
The practical headline: "Smith" and "Schmidt" get different Metaphone codes (SM0 and XMT respectively), even though Soundex incorrectly gives both S530. For any application where that distinction matters — name disambiguation, identity matching, search recall — Metaphone is a meaningful upgrade.
How it works
Metaphone processes a word character by character from left to right, applying a set of ordered rules. The output alphabet uses standard consonant letters plus 0 (representing the “th” sound, as in thin) and X (representing the “sh” or “ksh” sound, as in shoe or axe).
Vowels. All vowels (A E I O U) are dropped from the output. The one exception: if the word begins with a vowel, that vowel is retained as the first character of the code.
Initial letter sequences. Several two-letter openings are treated as a unit before the main loop begins:
AE,GN,KN,PN,WRat the start of a word — the first letter is silent and dropped."Knight"encodes as if it starts withN.
Consonant rules (applied in left-to-right order):
| Input | Rule | Output |
|---|---|---|
B |
Silent after M at end of word (dumb, lamb) |
drop |
C |
Before KN at word start |
drop |
C |
In -CIA-, -CH- |
X |
C |
Before E, I, Y |
S |
C |
Otherwise | K |
CK |
Always | K |
D |
Before -GE, -GI, -GY |
J |
D |
Otherwise | T |
G |
Before H when not at end and H is not before a vowel |
drop |
G |
In -GN, -GNED at end of word |
drop |
G |
Before E, I, Y (single G) |
K |
G |
Otherwise | K |
H |
Before a vowel or at end after a vowel | drop |
H |
Otherwise | H |
PH |
Always | F |
Q |
Always | K |
S |
Before -IA, -IO |
X |
S |
Before -CH |
SK |
S |
Otherwise | S |
T |
In -TIA, -TIO |
X |
T |
In -TCH |
drop |
T |
Otherwise | T |
TH |
Always | 0 |
W |
Before a vowel | drop |
W |
Otherwise | keep |
X |
At word start | S |
X |
Otherwise | KS |
Y |
Unless immediately before a vowel | drop |
Z |
Always | S |
Adjacent duplicate suppression. After applying all character rules, any run of the same output symbol is collapsed to a single instance. This mirrors Soundex’s deduplication step and handles doubled consonants and same-sound transitions.
[illustrate: step-by-step Metaphone encoding of “Thompson” — each character shown in a labelled cell with the rule applied annotated below it (T→T, H→drop after consonant before vowel, O→drop vowel, M→M, P→P, S→S, O→drop, N→N), the output string building character by character to the right, final code TMPSN highlighted]
Example
Smith and Schmidt — the key distinction from Soundex
Smith
S → S
M → M
i → drop (vowel)
th → 0 (TH rule)
Metaphone: SM0
Schmidt
Sch → X (SCH → X)
M → M
i → drop (vowel)
d → T (D → T, not before GE/GI/GY)
t → T (duplicate of previous T — collapse)
Metaphone: XMT
SM0 ≠ XMT. Metaphone correctly separates these two names. Soundex gives both S530.
Thompson
T → T
h → drop (H before vowel O)
o → drop (vowel)
m → M
p → P
s → S
o → drop (vowel)
n → N
Metaphone: TMPSN
Katherine
K → K
a → drop (vowel; word starts with K, not a vowel, so no initial-vowel retention)
th → 0
e → drop
r → R
i → drop
n → N
e → drop
Metaphone: K0RN
Pfister
P → P
f → F
i → drop
s → S
t → T
e → drop
r → R
Metaphone: PFSTR
[illustrate: two-column before/after comparison for “Smith” and “Schmidt” — left column shows Soundex encoding where both converge on S530 with the collision labelled; right column shows Metaphone encoding where Smith traces to SM0 and Schmidt traces to XMT, the divergence point annotated at the SCH→X rule]
Variants and history
Philips published Metaphone in Computer Language, Vol. 7, No. 12, December 1990. It was the first widely adopted phonetic algorithm to replace digit-class groupings with genuine phonological rules.
In 2000, Philips published Double Metaphone, which extends the original in two significant ways: it generates two codes per input — a primary and an alternate — to cover words with genuinely ambiguous pronunciation, and it adds rules for Slavic, Germanic, Celtic, and Hispanic name patterns that the original Metaphone handles poorly. For most new implementations, Double Metaphone is the recommended default.
NYSIIS (New York State Identification and Intelligence System) is a contemporary alternative to Metaphone, developed independently for US law-enforcement name matching. It produces single-character-per-position codes and is generally considered more accurate than Soundex for American names, though less sophisticated than Double Metaphone.
When to use it
Prefer Metaphone over Soundex when:
- You need to distinguish names like
"Smith"and"Schmidt"that Soundex incorrectly conflates. - Your name corpus includes words with silent letters, digraphs, or context-sensitive consonants that Soundex’s digit-class table cannot model.
- You are not constrained to a database that provides Soundex natively and can afford to add a library or plugin.
Prefer Double Metaphone over original Metaphone when:
- Your corpus is multilingual or includes names with non-English phonological origins. Metaphone, like Soundex, was designed for English names and applies English-only rules.
- You want two candidate codes per name rather than one, giving higher recall in ambiguous cases.
- You are building anything new — Double Metaphone is the mature successor and there is no practical cost to choosing it over the original.
Prefer edit-distance measures (Levenshtein, Damerau–Levenshtein) when:
- The variation in your data is typographic rather than phonetic — transpositions, substitutions, and insertions caused by keyboarding errors rather than spelling-by-ear. Phonetic algorithms do not model these well.
Variable-length codes and matching strategy. Because Metaphone produces variable-length output, you cannot use partial-code matching heuristics (such as “match on the first three digits”) the way some Soundex deployments do. Equality comparison on the full code is the only reliable strategy. This makes indexing straightforward — store the Metaphone code as a keyword field and query by exact value — but means you cannot implement ranked closeness from the code alone.
Python. The jellyfish library provides a clean implementation:
import jellyfish
jellyfish.metaphone("Smith") # "SM0"
jellyfish.metaphone("Schmidt") # "XMT"
jellyfish.metaphone("Katherine") # "K0RN"
The phonetics package is an alternative if you want Metaphone alongside other algorithms in one dependency:
import phonetics
phonetics.metaphone("Thompson") # "TMPSN"
Elasticsearch and OpenSearch. Install the analysis-phonetic plugin, then configure a phonetic token filter with "encoder": "metaphone":
{
"settings": {
"analysis": {
"filter": {
"metaphone_filter": {
"type": "phonetic",
"encoder": "metaphone",
"replace": true
}
},
"analyzer": {
"metaphone_analyzer": {
"tokenizer": "standard",
"filter": ["lowercase", "metaphone_filter"]
}
}
}
}
}
Set "replace": false if you want both the original token and the Metaphone code indexed on the same field — useful for a single-field strategy that handles both exact and phonetic matches without a separate subfield.
For new Elasticsearch or OpenSearch deployments, consider "encoder": "double_metaphone" instead. The configuration is identical; only the encoder value changes.