This is simple people. Make autocomplete beautiful within the client side of the web application is straightforward. You will find lots of plug ins.
But, within the backside, within the server side, what's the easiest method to get it done? I do not like the thought hitting the DB with every keypressed through the user.
I have been considering sphinx, or some full-text internet search engine running parallel out of your site.
For instance, if i've got a PHP (high traffic) site, i can produce a parallel python script that will get http demands from the "autocomplete textboxes". Then, whenever a user is pressing a type in the customer side, the AJAX demands are forwarded to that python script that may make use of a special strategy.
What's your aproach?
- Do not hit the DB. I am talking about, get the request and make a move Choose * FROM foo WHERE bar LIKE "req%" isn't a great answer. It might be a great strategy, but i understand how to get it done.-
- Duplicated data could be a sensible choice.
I actually do agree you need to possess some better solution. Apache solr includes a "suggestion" feature which you can use pretty much. In case your data set is small then invest the information in memory and merely perform a simple loop.
Around the front-end, I suggest using setTimeout() to hold back for around 200ms before firing the ajax call. If for the reason that 200ms, another key stroke is triggered, then cancel the final timeout and begin a different one. This can be a really clean solution where it can't hit the db with every key stroke. I have tried personally it previously and delay pills work very well.
This describes solr with jquery and just how to produce an autocomplete very well. http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/
That's one server hit per area per page (and only when the consumer types within the area), and you will cache it around the server therefore it rarely needs to hit the DB.
Edit: Caching around the server is really a large win since the list is identical for each request as well as for all customers, but better still, which means you can cache their email list within the client's browser while on an
Etag header having a appropriate period within the response. Thus the consumer could possibly get limitless autocompletion for starters (well-cached) server hit for the whole duration of the browser cache.