Executing database query "Smart"?
I have the following requirement.
I have a table with a column that contains city names. I'm going to do a city search.
But the user cannot enter the city name correctly.
Examples: City "Matara" is sometimes pronounced "Mathara". The city of Nuwara Eliya is sometimes called Nuwaraelia
I can keep consistency on the database column, but I want to get images back even if the end user is using an alternate word.
How should I use this method to use it effectively?
source to share
You should probably do a line distance check like Levenshtein distance
Additional approaches can be found here: How do you implement "Did you mean"?
source to share
You want something like a phonetic search. There are several algorithms. You can get an overview here
The idea is to add a column to your table with the phonetic equivalent of your city, and search against that (after performing the same function for the term you are looking for).
Some DBMSs, such as Oracle, have a pre-implemented SOUNDEX function that can allow you to perform searches without the added column.
source to share