Paul Joseph Davis

CouchDB View Indexing

Note:

This was part of an experiment I tried awhile back. There hasn't been any interest in including it in trunk and I don't really think it should be. So this is up for reference, but you probably shouldn't think about using this.

Overview

This is a fun little patch I wrote today for indexing CouchDB Map/Reduce views. The CouchDB path allows you to setup a process that will listen for Key/Value pairs being added and removed from a view so that you can keep an external index in sync. The patch also exposes a url that you can use to query the view.

Installation

A real quick nothing-goes-wrong type of installation would be along the lines of the following:

$ cd /usr/local/src/temp
$ git clone git://github.com/davisp/couchdb-lucene.git
$ cd couchdb-lucene
$ git checkout -b view_indexer origin/view_indexer
$ ant
$ cd ../
$ git clone git://github.com/davisp/couchdb.git
$ cd couchdb/trunk
$ git checkout -b index_server origin/index_server
$ ./bootstrap && ./configure && make
$ sudo make install

Config file: /usr/local/etc/couchdb/local.ini

; CouchDB Configuration Settings

[couchdb]
;max_document_size = 4294967296 ; bytes

[httpd]
;port = 5984
;bind_address = 127.0.0.1

[log]
level = debug

[daemons]
index_servers={couch_index_servers, start_link, []}

[index_servers]
fti=/usr/local/src/temp/couchdb-lucene/bin/couchdb-lucene-index

[httpd_db_handlers]
_index = {couch_httpd_view, handle_index_req}

Pay special attention to line 17 if you changed where you built couchdb-lucene.

Example Design Document

{
    "_id": "_design/foo",
    "_rev": "999203757",
    "views": {
        "bar": {
            "map": "function(doc) {emit(doc.id,doc.value);}",
            "index": "fti"
        }
    }
}

Querying the View

$ # Generate some data
$ curl http://127.0.0.1:5984/dbname/_index/fti/foo/bar?q="my query"

Supported Options

CouchDB-Lucene View-Indexer supports the following URL parameters:

  1. q -> Text query to pass to lucene. Supports the full Lucene syntax (ala org.apache.lucene.queryParser.QueryParser)
  2. count -> Number of documents to return
  3. skip -> Number of documents to skip