Pergunta

I am using this code to create an instant search for my site...

http://woorkup.com/2010/09/13/how-to-create-your-own-instant-search/

Some of the phrases in our database our very complex and can be easily misspelt so on top of this I wanted to use spelling suggestions.

Does anyone know of any ways to offer correct spellings based on a string provided?

Any help would be greatly appreciated.

Foi útil?

Solução

If someone searches for a phrase, doesn't click any of the results, and then researches with a new similar phrase (check out levenshtein()) and does click a result, write to your database the original phrase and the new phrase.

Record each time this happens. If the phrase is already matched, increment a counter for that phrase.

Then, if someone searches for a phrase that matches one of your possibly incorrect phrases (perhaps have a threshold using your counter), you can display a Did you mean to search for...? as well as the results (if any) for the incorrect phrase.

This isn't a spell check per se, but I think it would be useful to pick up on common mistakes. Unfortunately though, you probably don't have as many people to help you build an index like Google's Did you mean?

Outras dicas

Yes there is a jQuery plugin called After the Deadline.

Peter Norvig has written (and explained) a fairly basic spelling corrector; which makes for a very interesting read. It's in Python, but his explanations are invaluable (He does work for Google and this is a very bare bones representation of the Google did you mean algorithm).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top