Link to home
Start Free TrialLog in
Avatar of practitioner
practitionerFlag for Singapore

asked on

MySQL query, get the closest if exact not found

Hi,

How do I write a query that returns the closest / best matches if exact is not found? The best implementation can be seen on google.com that says "Did you mean _______" Now a days they have changed it and show the result for the correct keyword by default and shows "Search instead for ________" below it.

E.g. searching for:
fung shui
fungshwe

or any other spelling variation always results in correct one i.e. feng shui

Thanks
Avatar of Jim P.
Jim P.
Flag of United States of America image

Basically you would have to build up an index table that has the correct word and the variants that are off. Then you also have have to build a probability function so if someone were to type in "italian piza seattle" that you feed back the says "Did you mean pizza, Seattle Washington?" versus "Did you mean Pisa Italy?"
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of practitioner

ASKER

Thanks Tomas, Soundex function is the key.

Thanks jimpen, building an index is very difficult, although soundex is the implementation I need at the moment, I would love to know the best approach to build such an index automatically, I believe Google wouldn't have done this manually because it's almost impossible.