django-haystack + Whoosh SearchQuerySet().all() always None

删除回忆录丶 提交于 2020-01-05 05:55:19

问题


I am using:

django: 1.9.7
django-haystack: 2.5.0
whoosh: 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 }}

in the views.py i try:
SearchQuerySet().count() => returns 0
SearchQuerySet().all() => returns None

I've read about some issues with the latest Whoosh implementation in django-haystack but i'm not sure if the problem is in my code


回答1:


Please see my answer here:

Django Haystack & Whoosh Search Working, But SearchQuerySet Return 0 Results

There is a bug in Django-Haystack with Woosh that means if you use an Ngram or EdgeNGram field SearchQuerySet().count() and SearchQuerySet().all().count() will always return 0 unless you specify a filter.

e.g.

SearchQuerySet().all().count()
>> 0

SearchQuerySet().all().exclude(content='thisshouldnotmatchanything').count()
>> 14 [the total number of indexed objects]


来源:https://stackoverflow.com/questions/38913004/django-haystack-whoosh-searchqueryset-all-always-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!