Sponsored by:

Offer Alternate Spellings

If you have a web tool that takes any sort text input for a search, you might find value in intelligently offering alternate spellings.

This technique is best used with an indexed list of proper words where it may be common to misspell based on phonetics. It is not meant to be applied to serial numbers.

First, create a new column in your index table for your alternate spelling key. Then, create a small batch script that fetches every entry from your index and runs the PHP metaphone() function on it. Store the resultant value in the new column you created. Also, make sure you update the code that adds new data to the table to populate your new column.

Now that you have your alternate spelling column populated, simply query the database with a metaphone() of the search term when a search turns up no results. You now have very rudimentary “did you mean” functionality, but it doesn’t stop there.

PHP’s metaphone() is an okay means of getting words similar to one another. In short, it boils the word down to a very basic pronunciation form where “buyh” and “bowwow” are alike. As you can see, metaphone can be far too general. What we need to do next is pick only the most relevant results from the similar words query.

The next step in finding more specific data is to find the words most similar to the one the user originally provided. I use the PHP levenshtein() function which calculates the difference between two strings. Simply ranking the results of the metaphone query by their levenshtein difference will provide you with a reasonable means of emulating the spelling correction/suggestion code used by popular search engines and spell checkers. This final step whittles words similar to “buyh” down to a manageable few, several of which may indeed be what you really meant.

For a demonstration of this type of code in action, check out my Compact Online Dictionary which I built for testing such ideas. The entire application spans only 100 lines of code and includes user-based result relevance ranking.

2 Responses to “Offer Alternate Spellings”

  1. Phyllis Says:

    I’m just trying to find out how to put 2 dots over a letter in a name to express the correct pronounciation. Example, my grandaughter’s name is Zoe. But it should have 2 dots over the “e” so it doesn’t look like the “e” is silent. The name is actually 2 syllables instead of one as it appears without being able to put those 2 dots over the correct letter. When asking my daughter in law how to do this, she said use your alternate spelling check list. Well, either I’m blind or it really isn’t here. I tried to bring it up and find it on my spell check on my email and it just isn’t there. How do I get it on my computer so when I’m typing an email that references my grandaughter I’ll be able to spell her name correctly?

  2. Phyllis Says:

    So how do I obtain or access alternate spell check on my email?

Leave a Reply