首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django-haystack给出错误,无法在search/xapian/xapian_index打开索引

django-haystack给出错误,无法在search/xapian/xapian_index打开索引
EN

Stack Overflow用户
提问于 2012-08-02 08:13:56
回答 1查看 422关注 0票数 0

我正在尝试使用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中的以下模型:

代码语言:javascript
复制
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中有以下搜索索引:

代码语言:javascript
复制
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

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2012-08-03 08:21:56

您说您使用的是Haystack 1.2.4,但您链接到了新的2.x beta文档。在较早版本的Haystack中,您需要添加一个“自动发现”步骤。

它涉及到在settings.py中创建一个名为HAYSTACK_SITECONF的变量,该变量指向一个干草堆配置模块。在该模块中,您至少需要有以下几行:

代码语言:javascript
复制
import haystack
haystack.autodiscover()

请参阅适用于您的版本的教程:http://django-haystack.readthedocs.org/en/v1.2.4/tutorial.html

这会是问题所在吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11769365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档