Question

I have a list of airport names and my users have the possibility to enter one airport name to select it for futher processing.

How would you handle misspelled names and present a list of suggestions?

Was it helpful?

Solution

Look up Levenshtein distances to match a correct name against a given user input.

OTHER TIPS

http://norvig.com/spell-correct.html
does something like levenshtein but, because he doesnt go all the way, its more efficient

Employ spell check in your code. The list of words should contain only correct spellings of airports.

This is not a great way to do this. You should either go for a control that provides auto complete option or a drop down as someone else suggested.

Use AJAX if your technology supports.

I know its not what you asked, but if this is an application where getting the right airport is important (e.g. booking tickets) then you might want to have a confirmation stage to make sure you have the right one. There have been cases of people getting tickets for the wrong Sydney, for instance.

It may be better to let the user select from the list of airport names instead of letting them type in their own. No mistakes can be made that way.

While it won't help right away, you could keep track of typos, and see which name they finally enter when a correct name is entered. That way you can track most common typos, and offer the best options.

Adding to Kevin's suggestion, it might be a best of both worlds if you use an input box with javascript autocomplete. such as jquery autocomplete

edit: danish beat me :(

There may be an existing spell-check library you can use. The code to do this sort of thing well is non-trivial. If you do want to write this yourself, you might want to look at dictionary trie's.

One method that may work is to just generate a huge list of possible error words and their corrections (here's an implementation in Python), which you could cache for greater performance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top