[Answered ]-Django + Haystack how to do this search

2👍

So you’re basically looking for an OR type query right? By default haystack uses an AND operation for joining queries.

You can do this two ways:

  • Change HAYSTACK_DEFAULT_OPERATOR within your settings.py to be OR. This will obviously be a site-wide change.
  • Modify your SearchQuerySet form to use filter_or which will force the OR style lookup. So pass a new one into your form/view: SearchQuerySet.filter_or(**kwargs)

Apart from that, you could always join Django Q objects together but considering you have these options, those are probably your best bet.

For relevance, you should read the Best Practices page which goes into using search templates and making them be your way to show relevant content.

Hope that helps!

👤Bartek

Leave a comment