简体   繁体   English

SearchQuerySet()'或'查询

[英]SearchQuerySet() 'or' query

I'm having difficulty returning the results for an 'or' query in a SearchQuerySet() (django-haystack). 我很难在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? 这里可能是什么问题?

filter_or needs the parameters to all be enclosed in the same call. filter_or需要将所有参数都包含在同一调用中。 This should work instead: 应改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM