Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Haystack - Show results without needing a search query?

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

e.g. Show all products which are "blue" and between $10-$100.

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

Any ideas how I can get around it?

Thanks!

like image 326
RadiantHex Avatar asked Jun 11 '12 10:06

RadiantHex


1 Answers

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()
like image 140
ErezO Avatar answered Sep 19 '22 03:09

ErezO