Search Indexing in Javascript
David Hardtke
May 19, 2011
In order to leverage existing Lucene analyzers, our Search feature (currently in beta) makes use of Java views, rather than the traditional Javascript views you’re used to in CouchDB. Recently, we wanted to do some performance comparisons between the two; would the Java view server be significantly faster (or slower) than the Javascript view server on typical indexing tasks? To test this, we wrote a simple Javascript view (in the form of a CouchApp) that creates a Cloudant Search-compatible inverted index. The code is available on github here.
To use it, clone the git repository and use the couchapp tool to push it to your database:
$ git clone git@github.com:cloudant/jsindexer.git
$ cd jsindexer
$ couchapp push http://<user>.cloudant.com:5984/<db_or_couchapp_you_want_to_search>
With this simple push, you gain the ability to do a search against this inverted index. For example, if you want to search all the docs in that DB whose “comments” field contains “cloudant is awesome” and whose “rating” value is between 80 and 100:
$ curl 'http://<user>.cloudant.com:5984/<db_or_couchapp_you_want_to_search>/_search?q=comments:"cloudant is awesome" AND rating:[80 TO 100]&index=_design/jsindexer/_view/whitespace'
Obviously, that’s just scratching the surface. Our knowledge base has several articles about Search. You can go there to read our introduction to Search, learn more about the Search API or how to write your own Indexer.
As for the results of the performance comparison, our full text indexing speed is limited by the writing of the data to the CouchDB B-Tree, so Javascript and Java perform the same. So there you have it: full-text search from Javascript, a guilt-free geeky pleasure. Go ahead and have at it.