An example of marking up division lists using Sinatra and CouchDB.
- report.xml - the original provided demo file
- example.html - an example of the same content in HTML 5
- default.css - CSS file to make example.html a bit cleaner
To get this to work, you're going to need CouchDB, couchdb-lucene and couchapp. If you already have those, feel free to skip past the instally stuff
If you're on a Mac, CouchDBX is your best bet (or if you really must tinker, try this at your own risk); otherwise the nice folk over at CouchOne should have something for you
CouchApp is a great way to package up the inner workings of your CouchDB - views, fulltext indexes, that sort of thing - without pushing individual documents around by hand. Follow the installation instructions in the official README file
The search engine bit. Reasonably painful to set up, but worth the effort.
- Install Maven 2 if you don't already have it (good news fellow Mac-heads, nothing to do here). Everyone else you need to go over here
- Grab the couchdb-lucene code from the github repository (hit the download source button over in the top right)
- Unpack the couchdb-lucene code, open up a Terminal/iTerm/Command prompt window and navigate to the right directory
- Type
mvn
- Make some tea, this could take a while
- Navigate to the
target
subfolder and unpack the zip file you find in there - Rename the resulting folder
couchdb-lucene
and move it to where you want your couchdb-lucene app to live (I've put mine in/usr/local
) - Locate your CouchDB
local.ini
file (if you're using CouchDBX you need to right-click on CouchDBX in your Applications folder and select "Show Package Contents", from there it's in Contents / Resources / couchdbx-core / couchdb_VERSION / etc / couchdb) - Hack in the following:
[external] fti=/path/to/python /path/to/couchdb-lucene/tools/couchdb-external-hook.py [httpd_db_handlers] _fti = {couch_httpd_external, handle_external_req, <<"fti">>}
- Under [couchdb] change os_process_timeout as follows:
os_process_timeout=60000 ; increase the timeout from 5 seconds.
- Save the ini file and restart CouchDB
- Start CouchDB (if it isn't already running)
- Grab a Terminal window and navigate to the db folder
- Run
couchapp push http://localhost:5984/divisionlists
- Run
rake load_data
- In a new Terminal window, navigate to your couchdb-lucene folder
- Run
bin/run
As well as using the app search (which is pretty basic at the moment) you can query the lucene index directly:
http://localhost:5984/divisionlists/_fti/_design/data/main?q=Roman
http://localhost:5984/divisionlists/_fti/_design/data/main?q=constituency:Essex
http://localhost:5984/divisionlists/_fti/_design/data/main?q=title:Lord
http://localhost:5984/divisionlists/_fti/_design/data/main?q=name:Christie
http://localhost:5984/divisionlists/_fti/_design/data/main?q=name:David
http://localhost:5984/divisionlists/_fti/_design/data/main?q=name:%22Winston%20Spencer%20Churchill%22
http://localhost:5984/divisionlists/_fti/_design/data/main?q=aye:%22winston%20spencer%20churchill%22
http://localhost:5984/divisionlists/_fti/_design/data/main?q=noe:%22winston%20spencer%20churchill%22