Sign in to follow this  
plywood

[web] Mimicking Google Suggest

Recommended Posts

Hi, I'd like to add what I am calling an autocomplete search field on my game site, that would work very similar to Google's Suggest query input. Basically, I've looked into a few things, like the Ajax Toolkit, but I figured it couldn't hurt to start by posting here to see if there are commonly-accepted approaches to getting what I need done. Essentially, the control would work as follows: (1) It looks like a HTML text input (<input type="text"...) (2) For each character that the user keys in, an Ajax message relays that character back to the server, which adds it to the previous entries (previous typed letters) and performs a new DB query. Matching records are returned via Ajax. (3) Matching records are displayed directly underneath the text field in a select/drop-down style fashion, allowing the user to click any record and have that item populate the field My whole web architecture is PHP-based, so whatever dlls, plugins, toolkits, etc. I use have to be compatible with that. Anybody have any ideas as to where I should start or what my general approach should be? What 3rd party components I should be using? Thanks for any-and-all help here! ~plywood

Share this post


Link to post
Share on other sites
That's essentially how I've done it. IMHO, the JS is much easier with some 3rd party library (jQuery, Prototype, etc) but your mileage may vary.

To really mimic Google's suggestions (or most search engines) you'll want to "guess" at common words or search terms instead of just doing "t%", "th%" queries. My sites haven't had a serious DB or wide enough content spread to require much work there, but it's one you'll want to consider before it becomes a huge performance hit.

Likewise, if the user input is matching whatever you've already displayed, no need for extra queries; if only some suggestions are invalidated get X new suggestions to replace the ones that no longer apply.

Any other info you can give about the actual searching might trigger something I forgot if you run into problems, I haven't touched any of that code in a long time.

Hope that helps!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this