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/search_indexes.py

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:

https://github.com/joncasdam/opentrials/commit/ebec768f275dfcf56db1cb40daf86014adf49ea5 https://github.com/bireme/opentrials/commit/4f00d02c780faf5c790f45853b0b2c8036f3ff5c

Updating the indexes

To incrementally update SOLR indexes after inserts, use:

$ ./manage.py update_index

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

To rebuild all SOLR indexes, use:

$ ./manage.py 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:

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