0

I am working on a function to allow searching people in the same city.

Since I am not looking forward into using geolocation, I have user input their city. So, in order to have people find each other they need to input the same city name.

Now, I am using a case-sensitive database so the strings need to match, so I was thinking to have a simplification procedure, like this:

- user inputs city "New York"
  ->new york
  ->newyork

What I am looking forward to do next, is to make sure that people who input "new yprk" as a typo mistake, still be able to find each other.

I do not want to reinvent the wheel so, is there a script out there that you know about that sort of "hashes" the words so that slightly different words count as the same?

Thanks in advance.

john smith
  • 541
  • 6
  • 24

2 Answers2

0

No, because being smart like that introduces a lot of false positives. Why dont you check your city agains a list of known cities, if it exists continue, else raise error

http://www.maxmind.com/en/worldcities

A

Arjen
  • 416
  • 4
  • 12
0

Unfortunately no way to do it without Geo location since cities are names, if those were arbitrary english language words you could've used some sort of spell checking library to produce matches and run the fixed query, but since those are cities you need a geolocation database.

Now there is a potential workaround of using a world database of cities as a dictionary for a spell checking library but I am not sure how accurate would that be. IF you dont expect huge amounts of traffic just use googles free tier geocoding or this is a free alternative:

http://wiki.openstreetmap.org/wiki/Nominatim#Reverse%5FGeocoding%5F.2F%5FAddress%5Flookup

Its just not possible to guess names without some sort of a dictionary or 3rd party service. Other ways would include using google predictions API and load it with all the city names but of course thats 3rd party too...

Feras
  • 2,114
  • 3
  • 20
  • 42