Jun 17, 2008

HOWTO: Did you mean…

Author: gaweee | Filed under: development, howto

I always thought it was really cool to have those “Did you mean <some other spelling corrected word>”? Took me long enough to finally chance upon how it works! Basically it uses sound functions: soundex, metaphone or levenshtein distance to match words.

Different database supports different possible implementations of the functions. A sample mySQL query would look like:

SELECT `name` FROM `organizations` WHERE SOUNDEX(`name`) = SOUNDEX('dog');

I’ve also seen some mysql stored procs that hack in a levenshtein distance calculation algorithm. This allows a even more dynamic and accurate match. Unfortunately, i’ve never gotten it to work. Do let me know if anyone has succeeded.


3 Responses to “HOWTO: Did you mean…”

  1. Silver Knight Says:

    Please disregard / delete my prior comment (and this one also), as upon mousing over the links to the functions in the post I can now see that they lead to the PHP website making my prior comment kinda pointless. ;)

  2. Silver Knight Says:

    Dunno exactly what you tend to use server-side, as I only just found your blog for the first time today, but in case you happen to use PHP, I thought I thought I’d mention that these functions are built in to PHP as well. Just one more place that one can look for this functionality besides their database. (I’m not sure, but I’d guess similar functions can also likely be found in or for Ruby, Python, and most common web scripting languages.)

  3. Beshr Says:

    Really nice, I’ve been looking around for something like this.
    Thanks :)

Leave a Reply