gregmarra/the-blue-alliance — pull request #149 by fangeugene (2012-07-20 05:50:21+00:00)
Title: Typeahead for Search

Search boxes autocomplete for team numbers, names, events, and event codes, and go directly to the proper page. Inputs that don't have autocomplete go to the old search page.

Right now all the data (all teams & events) is loaded by a single ajax call, which is super inefficient, but works and works quickly enough for now.

I tried implementing a trie, which worked amazingly, but the data structure wouldn't fit in a single memcache store.

I also tried creating separate memcache entries where the key was the first two letters of every single word in a team/event name, and the value was a list of all teams/events that had a word that starts with those two letters. The worst case would need 36*36=1296 separate memcache entries, but realistically we will only ever hit a few hundred. The problem with this implementation is that if a single pair of letters misses in memcache, we have to recalculate the entire data set again. And if an obscure pair of letters gets called infrequently, it will probably get pushed out of memcache so next time someone calls it it will cause us to recalculate the entire set again.

TLDR: I don't know how efficient we want to make this, so I'm leaving it at a crude but usable state.

Oh, and the reason why I have the extra typeahead.js file is because the default bootstrap one doesn't support ajax or an action when a result is selected.