Sunday, September 20, 2015

Installing couchdb-lucene on MacOS X

Install couchdb-lucene

The original documentation can be found at https://github.com/rnewson/couchdb-lucene. I basically followed this documentation but there are a few modifications I wanted to note/remember.

I've installed couchdb-lucene with Homebrew. You can obtain Homebrew from http://brew.sh/. I've actually installed CouchDb through Homebrew too.

https://github.com/rnewson/couchdb-lucene

Configure CouchDB local.ini file

I've configured /usr/local/etc/couchdb/local.ini with following settings below.

[couchdb]
os_process_timeout=60000 ;increase the timeout from 5 seconds.

[external]
fti=/usr/bin/python /usr/local/Cellar/couchdb-lucene/1.0.2/libexec/couchdb-external-hook.py

[httpd_db_handlers]
_fti = {couch_httpd_external, handle_external_req, <<"fti">>}

Start couchdb-lucene

To start couchdb-lucene temporary in the console window run following command:

/usr/local/opt/couchdb-lucene/bin/cl_run

To start couchdb-lucene in the background run following command:

/usr/local/opt/couchdb-lucene/bin/cl_run &

If you get a connection refused error it most likely means that couchdb-lucene is not running.

Restart CouchDB

Next you need to restart couchdb.

sudo launchctl stop org.apache.couchdb
sudo launchctl start org.apache.couchdb

Once you've done that you should see following output when running "ps ax" to display the processes. You should see the last line with the couchdb-external-hook.py. If you don't see this line it means that something is wrong with your local.ini configuration.

charms:bin$ ps ax | grep couchdb
  543   ??  S      2:31.28 /usr/local/Cellar/erlang/17.4/lib/erlang/erts-6.3/bin/beam.smp -Bd -K true -A 4 -- -root /usr/local/Cellar/erlang/17.4/lib/erlang -progname erl -- -home /Users/charms -- -noshell -noinput -os_mon start_memsup false start_cpu_sup false disk_space_check_interval 1 disk_almost_full_threshold 1 -sasl errlog_type error -couch_ini /usr/local/etc/couchdb/default.ini /usr/local/etc/couchdb/local.ini /usr/local/etc/couchdb/local.d/couchdb-lucene.ini -s couch
 1677   ??  Ss     0:00.06 /usr/local/Cellar/couchdb/1.6.1_1/bin/couchjs /usr/local/Cellar/couchdb/1.6.1_1/share/couchdb/server/main.js
 1898   ??  Ss     0:00.14 /usr/bin/python /usr/local/Cellar/couchdb-lucene/1.0.2/libexec/couchdb-external-hook.py

Indexing a document

I've created a new document over Futon and just pasted the following JSON in to it (you'll need to change javascript function to match parameters of your documents):

{
   "_id": "_design/search_station",
   "_rev": "1-e9b2c978433813a6d45010bac6de9971",
   "fulltext": {
       "by_name": {
           "index": "function(doc) { var ret=new Document(); ret.add(doc.name); return ret }"
       },
       "by_ip": {
           "index": "function(doc) { var ret=new Document(); ret.add(doc.ip); return ret }"
       }
   }
}

After that you should be able to run following CouchDb query:

http://localhost:5984/your-db-name/_fti/_design/search_station/by_name?q="Station1"
http://localhost:5984/your-db-name/_fti/_design/search_station/by_ip?q="192.168.3.14"

More

There is a lot more you can do with couchdb-lucene. For this please read the couchdb-lucene documentation

No comments:

Post a Comment