Django – Haystack – Solr — Setup Guide


I’ve been needing a search engine and tried Sphinx, Haystack-Whoosh, and Haystack-Solr.

I’m quite happy with Haystack-Solr based on the results it provides out of the box. Whoosh clearly needed some more configuration to weigh multiple OR matches higher.

TERM1 OR TERM2 OR TERM3 OR TERM4 should give a match the highest score that has all 4 terms but it didn’t.

First, install solr.

# I'm on a Mac, so I used homebrew
brew install solr

# ...if you're on Ubuntu install solr-jetty
apt-get install solr-jetty

Next install solr’s python bindings and django-haystack

pip install pysolr
pip install django-haystack

Configure django-haystack, set up the search index classes according to the docs

Add the required solr fields to (solr server location)

Setup Solr

Run the solr schema file generation management command and paste it into your solr config directory.

python build_solr_schema > solr_schema.xml

mv solr_schema.xml /usr/local/Cellar/solr/3.1.0/libexec/example/solr/conf/schema.xml

Start solr

cd /usr/local/Cellar/solr/3.1.0/libexec/example/
java -jar start.jar

Generate index

python rebuild_index

Done! Start using haystack

from haystack.query import SearchQuerySet
results = SearchQuerySet().auto_query('my search here')

3 thoughts on “Django – Haystack – Solr — Setup Guide

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s