Ubuntu - Django Haystack和Solr集成错误

时间:2012-07-11 14:39:22

标签: python django solr django-haystack

我已经阅读了这两个用于构建搜索应用的教程。

  1. 使用OpenJDK在{8}上安装Solr和django-haystack,here
  2. Django - Haystack - Solr - 设置指南,here
  3. 但是当我来的时候:

      

    配置django-haystack,根据设置搜索索引类   到文档

         

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

         

    将所需的solr字段添加到settings.py(solr服务器位置)

    我收到此错误(尝试导入haystack时):

    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.
    

    在python中导入haystack,错误:

    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.
    

    我已经使用sudo easy_install https://github.com/toastdriven/django-haystack/zipball/v1.2.7安装了haystack。

    我的django版本:1.4

    更新

    如果您在导入haystack时遇到类似错误的问题:

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

    尝试将您的项目导入为./manage.py shell而不是import haystack

1 个答案:

答案 0 :(得分:3)

Haystack 1.2.7不使用HAYSTACK_CONNECTIONS;只有Haystack 2.0+使用该设置。 Haystack文档默认使用开发版本(当前为2.0.0-beta),而不是当前的PyPi版本(1.2.7),因此您需要注意您正在查看哪个版本的文档。

然而,如果你想走那条路,那么Haystack 2.0.0-beta是完全可用的。我自己用它。你只需要从Github克隆它。最简单的方法是使用pip:

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

否则,只需下载“master”分支tarball,然后使用python setup.py install手动安装。