Django Haystack - Show results without needing a search query?

后端 未结 5 2224
情书的邮戳
情书的邮戳 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 11:10

    Look at SearchQuerySet.

    This should be possible if color and price has been defined in your SearchIndex:

    sqs = SearchQuerySet().filter(color="blue", price__range=(10,100))
    

    You can limit the query to certain models by adding models(Model) to the SearchQuerySet. So if you want to limit your query to the model Item use:

    sqs = SearchQuerySet().filter(color="blue", price__range=(10,100)).models(Item)
    

提交回复
热议问题