Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 嗖嗖+django haystack缺少搜索结果_Python_Django_Postgresql_Django Haystack_Whoosh - Fatal编程技术网

Python 嗖嗖+django haystack缺少搜索结果

Python 嗖嗖+django haystack缺少搜索结果,python,django,postgresql,django-haystack,whoosh,Python,Django,Postgresql,Django Haystack,Whoosh,我正在使用相对简单的Whoosh 2.6和django haystack 2.3.1实现来搜索联系人对象。然而,对mary的示例搜索只返回我的许多mary联系人中的一小部分。以下是相关文件: search_index.py contact_text.txt和contact_content_auto.txt都相同 views.py 相关说明: 为了简单起见,省略了一些代码 模板有if语句,以便在搜索索引中去掉单词None 目前,我的所有联系人对象都具有有效的全名 没有返回和不返回mary结果的模式

我正在使用相对简单的Whoosh 2.6和django haystack 2.3.1实现来搜索联系人对象。然而,对mary的示例搜索只返回我的许多mary联系人中的一小部分。以下是相关文件:

search_index.py contact_text.txt和contact_content_auto.txt都相同 views.py 相关说明:

为了简单起见,省略了一些代码 模板有if语句,以便在搜索索引中去掉单词None 目前,我的所有联系人对象都具有有效的全名 没有返回和不返回mary结果的模式:从contact\u contact中选择count*,其中lowerfull\u名称如下 “%mary%”;返回97行,而搜索仅返回5行。 同样,对于483个john联系人,搜索返回19个。 使用Python 2.7、Django 1.5和Postgres 8.4
你记得更新索引吗?@Eldamir-当然记得。我已经从嗖嗖升级到Elasticsearch,没有任何问题。
from django.db.models import Q
from haystack import indexes
from apps.contact.models import Contact

class ContactIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    full_name = indexes.CharField(model_attr='full_name', null=True)
    email = indexes.CharField(model_attr='email', null=True)
    phone = indexes.CharField(model_attr='phone', null=True)
    content_auto = indexes.NgramField(use_template=True)
    # several more indexed=False fields to avoid db hits later

    def get_model(self):
        return Contact

    def index_queryset(self, **kwargs):
        # one of full_name, email, phone has to be non-null   
        return self.get_model().objects.filter(
            Q(full_name__isnull=False) | Q(email__isnull=False) | Q(phone__isnull=False))

    def get_updated_field(self):
        return 'date_modified'
{% if object.full_name %}{{ object.full_name }}{% else %}{% endif %}
{% if object.email %}{{ object.email }}{% else %}{% endif %}
{% if object.phone %}{{ object.phone }}{% else %}{% endif %}
def search(request):
    sqs = SearchQuerySet()
    form = SearchForm(request.POST, searchqueryset=sqs, load_all=False)
    if form.is_valid():
        return form.search()