MongoDB + Node.js + AJAX solution for doing autocomplete search MongoDB + Node.js + AJAX solution for doing autocomplete search mongodb mongodb

MongoDB + Node.js + AJAX solution for doing autocomplete search


I don't think a trie will work. Trie's usually operate from the beginning of a string. So if you used a trie to index your headlines, a user typing 't' would only be able to search a trie for headlines that started with t. I think the best bet for using mongodb, unless you've got huge amounts of text, is simply to use regular expressions in conjunction with the $or operator.

On the change event in a text input box, you'll want to make an AJAX request, as you said, to your node server which will issue the query to mongodb and return the results in a JSON array.

Regular expressions in mongo: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions

$or operator:http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24or

A demo of how jQuery UI handles auto complete (for reference on the AJAX request and filling in values):http://jqueryui.com/demos/autocomplete/