我正在尝试使用django-haystack和xapian后端在我的django站点上设置一个搜索功能。我按照下面的说明操作:http://django-haystack.readthedocs.org/en/latest/tutorial.html
输入搜索时抛出错误: Unable to open index at search/xapian/xapian_index
当我运行./manage.py rebuild_index时,似乎没有创建搜索索引,但是,当时没有报告错误。
我正在尝试索引myapp/models.py中的以下模型:
class MyMsg (models.Model):
msg = models.TextField(max_length=2000)
pub_date = models.DateTimeField('date published')
author = models.ForeignKey(User)
def __unicode__(self):
return self.msg我在myapp/ search _index.py中有以下搜索索引:
class MyMsgIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='author')
pub_date = indexes.DateTimeField(model_attr='pub_date')
def get_model(self):
return MyMsg
def index_queryset(self):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now())我使用的是: haystack 1.2.4 xapian 1.2.12 mac OS X 10.6.8
提前感谢您的帮助。
发布于 2012-08-03 08:21:56
您说您使用的是Haystack 1.2.4,但您链接到了新的2.x beta文档。在较早版本的Haystack中,您需要添加一个“自动发现”步骤。
它涉及到在settings.py中创建一个名为HAYSTACK_SITECONF的变量,该变量指向一个干草堆配置模块。在该模块中,您至少需要有以下几行:
import haystack
haystack.autodiscover()请参阅适用于您的版本的教程:http://django-haystack.readthedocs.org/en/v1.2.4/tutorial.html
这会是问题所在吗?
https://stackoverflow.com/questions/11769365
复制相似问题