I work on a site that sells let say stuff and offers "seller search." In this search, you enter your city or zip code or region and distance (in km or miles), then the site gives you a list of suppliers.
For this, I have a database with suppliers. In the form for saving these providers, you enter the full address, and when you click the "Save" button, a request for Google maps is made in order to get their latitude and longitude.
When someone performs a search, I look at the table where I store all the search terms and their lat / lng. This table looks like
+--------+-------+------+ | term | lat | lng | +--------+-------+------+
So the first request is very simple
select lat, lng from my_search_table where term = "the term"
If I find a result, I then search with a good method for all the suppliers in the range that the visitor wants, and print the result on a map.
If I can’t find the result, I search using the levenshtein function, because people writing bruxelle or bruxeles instead of bruxelles are something really common I don’t want to constantly query google maps (I also have a column “how many times time "in my table to get some statistics).
So I request my_search_time without a where clause and go through all the results to get the smallest levensthein distance. If the smallest result is greater than 2, I request coordinates from google maps.
Here is my problem. For some countries (we have several sites around the world), my_search_table has 15-20k + entries ... and php doesn’t (really) look like such entries (which I understand very well), and my request is timed out php, I could increase this timeout, but the problem will be the same for several months.
So, I tried the MySQL levensthein function (found in https://stackoverflow.com/a/13677/ ... btw), but it is also very slow.
So my question is: "Is there a way to quickly do this search even on very large datasets?"