views:

126

answers:

2

Hi,

I know that this question has maybe been asked several times but I have search several days without getting any satisfying answer.

Some sites, like eventful.com, etc. have a autosuggest city field with cities from around the world (even small cities in small countries from Tunisia).

I'm wondering how they achieve it. I've a text list of country + city from around the world but it's 250Mo so I guess the data is not contained in any javascript. Even a database call will be too ressource consuming I guess

Do you have an idea on how they achieve that?

+4  A: 

They are using AJAX to send a shorten list of possible matches when you've typed the first 2-3 letters of the city you want.

AJAX queries the server, the server searches the database (I don't see how 250Mo is expensive), and then returns the results to the browser, which then displays it to the user (via JavaScript).

Andrew Moore
A: 

If you want to save the cost of going to the database all the time cache this data as a flat file in JSON format and load it via an AJAX request. Update the file from the db whenever it changes or daily or something like that. Populate your dropdown from the JSON data. You can loop through the array and add/remove suggestions as the user types.

Swish
And transfer 1 - 1.5MB of suggestions per keystroke? What a bad idea... Suggestions are based on way more than just the keystrokes the user keys in. Geolocation and previous choices all have a part in it.
Andrew Moore
If you're going to cache the data, memcached should be used to store the results, or at most, store a few hundred of the most commonly searched cities on the client.
Dana the Sane