Django Haystack - Show results without needing a search query?

后端 未结 5 2235
情书的邮戳
情书的邮戳 2021-02-08 10:46

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

5条回答
  •  长发绾君心
    2021-02-08 10:54

    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()
    

提交回复
热议问题