【问题标题】:Django-haystack with whoosh带有嗖嗖声的 Django 干草堆
【发布时间】:2011-11-07 12:47:30
【问题描述】:

我得到 SearchBackendError at /forum/search/ No fields were found in any search_indexes. Please correct this before attempting to search.

search_indexes放在djangobb应用根目录下:

from haystack.indexes import *
from haystack import site

import djangobb_forum.models as models

class PostIndex(RealTimeSearchIndex):
    text = CharField(document=True, use_template=True)
    author = CharField(model_attr='user')
    created = DateTimeField(model_attr='created')
    topic = CharField(model_attr='topic')
    category = CharField(model_attr='topic__forum__category__name')
    forum = IntegerField(model_attr='topic__forum__pk')

site.register(models.Post, PostIndex)

settings.py

# Haystack settings 

HAYSTACK_SITECONF = 'search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'djangobb_index')

我在安装的应用程序中也有 haystackwhoosh
在python解释器中:

>>> import haystack
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.../lib/python2.7/django_haystack-1.2.5-py2.5.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.

有人有什么想法吗?提前感谢您提供的任何帮助。

【问题讨论】:

    标签: django-haystack whoosh


    【解决方案1】:

    请注意,文档中显示的 HAYSTACK_SITECONF 值只是一个示例。真实名称应该是定义 SearchIndex 派生类的模块。所以,在你的情况下,模块是 search_indexes,那么你应该有HAYSTACK_SITECONF='search_indexes' 另外,关于解释器上出现的那个错误,你是用python ./manage.py shell 得到的吗?如果没有,则解释器未加载 settings.py。

    【讨论】:

    • 很抱歉这么晚才回答,但我在其他地方有点忙。我没有使用 2.0.0-alpha 版本。我给出了一些我尝试导入 haystack 时遇到的错误(请查看我的问题描述)
    • 好的,我相应地重写了答案
    • python ./manage.py shell 之后我导入 haystack 并输入 '>>> haystack.__version__' 并得到(1, 1, 0),我也定义了HAYSTACK_SITECONF='search_indexes' 但这次我得到No fields were found in any search_indexes. Please correct this before attempting to search. 这是一件很难的事情.请问您有什么想法吗?
    • 您是否为“文本”属性定义了模板?请注意,haystack 希望您使用它的约定来放置文件的位置和命名方式,否则您必须使用 arg template_name 或设置 use_template=False。对于后者,您还必须改用 arg model_attr。
    • 记录一下:我使用的是 1.2.5 版本,这是最新的标签,所以结果可能会有所不同。 github.com/toastdriven/django-haystack/tags
    猜你喜欢
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    相关资源
    最近更新 更多