Reverse of soundex in mysql

1k views Asked by At
select SOUNDEX('ram')

WILL RETURN 'R500'

Is there a way to input 'R500' and return 'ram'

something like this

select reverse_of_SOUNDEX('R500')

RESULT
--------
ram
2

There are 2 answers

0
paxdiablo On

You have the same problem as you would have for trying to reverse any many-to-one mapping function.

While ram may be one word that gives you the soundex code r500, so do a large number of other words (ran, rim, run, rune, rain and so on, depending on which variant of soundex you're using).

So which word would you like to see displayed in that case?

One possibility, if you're after a list of words, would be to populate a table with a large number of words (from a dictionary somewhere) along with their soundex codes. The codes can be set, after insertion of the words, quite easily with:

update sxmap set sxcode = soundex(word)

and then you can simply do:

select word from sxmap where sxcode = 'R500'

or:

select word from sxmap where sxcode = soundex('ram')
0
Mitch Wheat On

A Soundex mapping is essentially a Hash code (i.e a many-to-one mapping).

As such it is not uniquely reversible.

There are several words that can soundex map to R500, you cannot tell which was the original before mapping.