我到了
SearchBackendError at /forum/search/
No fields were found in any search_indexes. Please correct this before attempting to search.
将search_indexes
放在djangobb
app根目录中:
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')
我也在我安装的应用中使用了haystack
和whoosh
在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.
有人有什么想法吗?提前感谢您提供的任何帮助。
答案 0 :(得分:1)
请注意,HAYSTACK_SITECONF文档中显示的值仅为示例。实名应该是定义SearchIndex派生类的模块。因此,在您的情况下,模块是search_indexes,那么您应该HAYSTACK_SITECONF='search_indexes'
另外,关于解释器中出现的错误,您是否使用python ./manage.py shell
得到了错误?如果没有,则解释器未加载settings.py。