SearchQuerySet() 'or' query

453 views Asked by At

I'm having difficulty returning the results for an 'or' query in a SearchQuerySet() (django-haystack).

In some cases it works but in others it doesn't, so I'm wondering if it's an issue with how I'm calling the 'or' query.

Currently, I want to match restaurants that are in the category that a user searches for + a free form search of that category. This is what I have:

restaurants = SearchQuerySet().filter_or(category__name=self.query)\
                            .filter_or(content=Raw(self.query))\
                            .order_by('-weight')\
                            .models(Restaurant)

Essentially, the results returned should be (category results) + (free form results). What could be the issue here?

1

There are 1 answers

0
AudioBubble On

filter_or needs the parameters to all be enclosed in the same call. This should work instead:

restaurants = SearchQuerySet().filter_or(
                                category__name=self.query,
                                content=Raw(self.query)
                             ).order_by('-weight').models(Restaurant)