3

我正进入(状态 SearchBackendError at /forum/search/ No fields were found in any search_indexes. Please correct this before attempting to search.

放置search_indexesdjangobb应用程序根目录中:

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)

设置.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.

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

4

1 回答 1

1

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

于 2011-12-05T21:44:28.217 回答