Django Haystack-显示结果而无需搜索查询? [英] Django Haystack - Show results without needing a search query?

查看:79
本文介绍了Django Haystack-显示结果而无需搜索查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使没有插入搜索查询,我仍要显示与选定方面匹配的所有结果。类似于某些商店应用程序的工作方式,例如亚马逊

I would like to display all results which match selected facets even though a search query has not been inserted. Similar to how some shop applications work e.g. Amazon

例如显示所有蓝色且价格在$ 10- $ 100之间的产品。

如果未指定搜索查询,Haystack不会返回任何值。

Haystack does not return any values if a search query is not specified.

有什么想法可以解决吗?

Any ideas how I can get around it?

谢谢!

推荐答案

如果有人还在寻找,则建议在干草堆代码中提供一个简单的解决方案:

If anyone is still looking, there's a simple solution suggested in haystack code:

https://github.com/toastdriven/django-haystack/blob/master /haystack/forms.py#L34

class SearchForm(forms.Form):
    def no_query_found(self):
    """
    Determines the behavior when no query was found.

    By default, no results are returned (``EmptySearchQuerySet``).

    Should you want to show all results, override this method in your
    own ``SearchForm`` subclass and do ``return self.searchqueryset.all()``.
    """
    return EmptySearchQuerySet()

这篇关于Django Haystack-显示结果而无需搜索查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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