Search code examples
pythondjangosolrdjango-haystack

Ubuntu - Django Haystack and Solr Integration Error


I have read these two tutorials for building an search app.

  1. Installing Solr and django-haystack on Ubuntu with OpenJDK, here
  2. Django – Haystack – Solr — Setup Guide, here

but when i come to:

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

http://docs.haystacksearch.org/dev/tutorial.html#configuration

Add the required solr fields to settings.py (solr server location)

I get this error (when trying to import haystack too):

raise ImproperlyConfigured("You must define the HAYSTACK_SITECONF setting before using
         the search framework.")
django.core.exceptions.ImproperlyConfigured: You must define the HAYSTACK_SITECONF 
          setting before using the search framework.

Importing haystack in python, error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/django_haystack-1.2.7-py2.6.egg/haystack
     /__init__.py", line 26, in <module>
    raise ImproperlyConfigured("You must define the HAYSTACK_SITECONF setting before 
       using the search framework.")
django.core.exceptions.ImproperlyConfigured: You must define the HAYSTACK_SITECONF 
           setting before using the search framework.

I have installed haystack with sudo easy_install https://github.com/toastdriven/django-haystack/zipball/v1.2.7.

My django version: 1.4

UPDATE:

If you have troubles like this error when importing haystack:

ImportError: Settings cannot be imported, because environment variable
      DJANGO_SETTINGS_MODULE is undefined.

try to import in your project as ./manage.py shell rather than than import haystack.


Solution

  • Haystack 1.2.7 doesn't use HAYSTACK_CONNECTIONS; only Haystack 2.0+ use that setting. The Haystack documentation defaults to the development version (2.0.0-beta, currently), not the current PyPi release (1.2.7), so you need to be careful which version of the docs you're looking at.

    However, Haystack 2.0.0-beta is perfectly usable if you want to go that route, though. I use it myself. You just have to clone it from Github. The easiest way is with pip:

    pip install git+https://github.com/toastdriven/django-haystack.git#egg=django-haystack
    

    Otherwise, just download the "master" branch tarball an install it manually with python setup.py install.