0

我正在尝试使用带有 xapian 后端的 django-haystack 在我的 django 站点上设置搜索功能。我按照以下说明进行操作:http: //django-haystack.readthedocs.org/en/latest/tutorial.html

当我输入搜索时,它会引发错误:无法在搜索/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

提前感谢您的帮助。

4

1 回答 1

0

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

它涉及在settings.py调用HAYSTACK_SITECONF中创建一个指向 haystack 配置模块的变量。在该模块中,您至少需要具有以下几行:

import haystack
haystack.autodiscover()

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

这可能是问题吗?

于 2012-08-03T00:21:56.057 回答