Django-haystack 不更新索引

标签 django-haystack xapian

使用django-haystack 2.0.0和 xapian-haystack 2.0.0,迁移了 1.1.5 中的所有代码,如 docs 中所述。 现在我的 search_indexes.py 看起来像:

from haystack import indexes
from app.models import Post

class PostIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    def get_model(self):
        return Post

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(visible=True)

但是当我去rebuild_index时,它说:

Are you sure you wish to continue? [y/N] y

Removing all documents from your index because you said so. All documents removed.

冗长:

Skipping '<class 'django.contrib.auth.models.Permission'>' - no index.
Skipping '<class 'django.contrib.auth.models.Group'>' - no index.
...
Skipping '<class 'app.models.Post'>' - no index.

所以,我不知道为什么 haystack 不索引这个模型。

最佳答案

您必须实际将字段添加到索引中,因此在“文本”下添加:

post1 = indexes.CharField(model_attr='postfield1', null=True)

然后在您的 post_text.txt 索引文件模板中:

{{object.post1}}

现在应该可以工作了。

关于Django-haystack 不更新索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16074529/

相关文章:

django - 在SearchResult django haystack的数据库中找不到对象

solr - Xapian 的爬虫/解析器

lucene - 部分词的文档搜索

python - Django haystack 索引多对多字段,但如果有多个词则搜索失败

django - Django 的 Haystack 是什么?

带有 xapian 引擎的 Django-haystack : can't execute update_index if model has ManyToManyField

search-engine - solr 与 xapian : which one gives you the most meaningful results?

django - Haystack 与 Django 1.4 不兼容?

python - Django 干草堆测试

django - 如何使用 django-haystack 按字符串形式搜索整数字段(例如 "priority")?