How to Add Fields to the Search Index

OpenTrials uses the SOLR/Lucene search engine with the Haystack Django application. This document assumes some familiarity with those technologies.

Adding a field

1. Open the source file repository/

2. Add a haystack.index instance

A complete example

Two complete examples of how to insert a new field for advanced search can be found in these commits:

Updating the indexes

To incrementally update SOLR indexes after inserts, use:

$ ./ update_index

The command above should be invoked as a periodically as a cron job to index new

To rebuild all SOLR indexes, use:

$ ./ rebuild_index

To change the SOLR index schema, generate a new schema.xml, copy it to where SOLR needs it and restart Tomcat, the SOLR application server:

$ ./ build_solr_schema > solr/schema.xml
$ sudo cp solr/schema.xml /usr/share/solr/conf/schema.xml
$ sudo service tomcat6 restart