使用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/