django-haystack + Whoosh SearchQuerySet()。all()始终没有 [英] django-haystack + Whoosh SearchQuerySet().all() always None

查看:280
本文介绍了django-haystack + Whoosh SearchQuerySet()。all()始终没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:

django:1.9.7

django-haystack:2.5.0

whoosh: 2.7.4

django: 1.9.7
django-haystack: 2.5.0
whoosh: 2.7.4

search_index.py

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

user_text.txt

{{ object.last_name }}

在views.py我尝试:

SearchQuerySet()。count()=>返回0

SearchQuerySet()。all()=>返回无

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

我已经阅读了django-haystack中最新的Whoosh实现的一些问题,但我不知道问题是在我的代码中

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

推荐答案

请在这里看到我的答案:

Please see my answer here:

一个href =https://stackoverflow.com/questions/40378644/django-haystack-whoosh-search-working-but-searchqueryset-return-0-results/40380881#40380881> Django Haystack& Whoosh搜索工作,但SearchQuerySet返回0结果

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

Django-Haystack在Woosh中有一个错误,这意味着如果您使用Ngram或EdgeNGram字段SearchQuerySet ).count()和SearchQuerySet()。all()。count()将始终返回0,除非您指定过滤器。

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.

例如

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

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

这篇关于django-haystack + Whoosh SearchQuerySet()。all()始终没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆