Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use autocomplete for thousands of entries?

Is there a way to setup autocomplete in PHP/jQuery that can quickly run through thousands of rows in a database?

I have a job board where the user enters his/her college - and I want to offer autocomplete. Problem is, there are 4,500 colleges in the united states and a seems like an awful solution.

Is there a good way to both make the query fast, and return results only when there are less than 10 options available?

Thank you in advance, Walker

like image 521
Walker Avatar asked Jun 23 '10 22:06

Walker


1 Answers

I agree with Anax. You may want to look at a simple solution like the new jQuery UI Autocomplete field.

Using the delay and minLength options, you could keep the script from querying the server until the user has entered say three characters, which would reduce the number of results.

PS. There is also a caching option which may be useful. You could cache the entire list client-side lessening the calls to the database.

like image 130
TomWilsonFL Avatar answered Nov 03 '22 01:11

TomWilsonFL