views:

92

answers:

1

I have an online web application with a top menu tree for opening different widgets for performing different tasks. As the app grows more powerful, that tree has become large and difficult to navigate. I've implemented a search feature, where users can just type the menu name or part of it and I use regex to find all items in the menu tree that match what the user types. My regex allows for partial words and swapped words, and also limits the search to the beginning of each word. The one thing it doesn't allow for is misspelled words. I understand that to allow for misspelled words it's best not to use regex and to use a string distance method instead, but I still want to allow for the partial word and swapped words. Is this possible?

For example, right now, if a menu item is "Finance Rate Maintenance", any of the following would match to that menu item: "finance", "finance ra", "rate finance" etc.. "inance rate" would not match because "inance" does not appear at the beginning of any of the words for that menu item. I want searches like "fnane rate" and "rate maintainance" which are slightly misspelled to match.

+1  A: 

I would just attach a list of words to each option, and simultaneously maintain a dictionary with all of the words in it. Then, when the user types in their query, the program would check that every word that they enter is in the dictionary. If one is not, it would find the closest word via. string distance and correct the word.

Finally, it would could suggest the menu option with the most words in common with the corrected input words.

A good example of a spelling corrector (in python though) is at http://norvig.com/spell-correct.html

hb2pencil
The general idea seems good, but the menu is generated dynamically upon login due to permissions, so I'd have to generate a dictionary upon login and store it in session. Could be done, and might be the best answer, but I was hoping for something a little more straightforward
Danny Cohn
I see what you mean, it does seem like a fair bit of work to get up and running. Generating the dictionary and searching would not be very computationally expensive though.
hb2pencil