MySQL 有個叫做 soundex() 的函式,這個函式會回傳字串發音的 fingerprint,藉由這個 fingerprint 來搜尋其他發音類似的字串。
先隨意挑幾個單字:
select soundex("depoart"), soundex("department")
+--------------------+-----------------------+
| soundex("depoart") | soundex("department") |
+--------------------+-----------------------+
| D163 | D16353 |
+--------------------+-----------------------+
depoart 和 department 在前半部有相同的發音,所以 soundex() 回傳的 prefix 是相同的。
如果換成一組完全不同的文字:
select soundex("space"), soundex("system")
+------------------+-------------------+
| soundex("space") | soundex("system") |
+------------------+-------------------+
| S120 | S350 |
+------------------+-------------------+
因為都是 s 開頭,所以回傳值都是 S,但後半部的值就不同了。
這個在查詢類似拼字錯誤上應該蠻有用的,像是:
select case
when soundex("john") = soundex("jone")
then 1 else 0
end
as familiar
+----------+
| familiar |
+----------+
| 1 |
+----------+