我正在使用:
django: 1.9.7
django-干草堆: 2.5.0
呼呼: 2.7.4
search_index.py
class ProfileIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
last_name= indexes.CharField(model_attr='last_name')
content_auto = indexes.EdgeNgramField(model_attr='first_name')
def get_model(self):
return User
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all() user_text.txt
{{ object.last_name }}在views.py中,我尝试:
SearchQuerySet().count() => returns 0
SearchQuerySet().all() => returns None
我读过关于django-haystack中的最新Whoosh实现的一些问题,但是我不确定这个问题是否在我的代码中。
发布于 2016-11-04 13:30:18
请看我在这里的回答:
Django Haystack & Whoosh Search Working, But SearchQuerySet Return 0 Results
Django-Haystack中存在一个bug,这意味着如果使用Ngram或EdgeNGram字段,则SearchQuerySet()、.count()和SearchQuerySet()、.all()、.count()将始终返回0,除非指定筛选器。
例如:
SearchQuerySet().all().count()
>> 0
SearchQuerySet().all().exclude(content='thisshouldnotmatchanything').count()
>> 14 [the total number of indexed objects]https://stackoverflow.com/questions/38913004
复制相似问题