使用或/||在太阳黑子搜索中
如何在太阳黑子搜索中使用“或”?
在我的代码中,我的
with(:location_id, current_user.location.path_ids || current_user.location.parent.descendant_ids)
搜索仅评估第一部分。
如果我将“current_user.location.path_ids”放在第一位(在 || 之前),我只会获得该搜索产生的记录。如果我将“current_user.location.parent.descendant_ids”放在第一位,我就会从该搜索中获得结果。我想要两者的结果。
我也尝试过
with(:location_id, current_user.location.path_ids || :location_id, current_user.location.parent.descendant_ids)
希望你能理解我的问题。
How can I use 'or' in a Sunspot search?
In my code I have
with(:location_id, current_user.location.path_ids || current_user.location.parent.descendant_ids)
The search only evaluates the first part.
If I put 'current_user.location.path_ids' first (before ||), I only get the records resulting from that search. If I put 'current_user.location.parent.descendant_ids' first, I get the results from that search. I want the results of both.
I have also tried
with(:location_id, current_user.location.path_ids || :location_id, current_user.location.parent.descendant_ids)
I hope you understand my question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
||
是一个 Ruby 运算符。这段代码基本上是在计算表达式current_user.location.path_ids || current_user.location.parent.descendant_ids
并将该值作为第二个参数传递给with
方法。查看太阳黑子自述文件。我认为你需要
any_of
:||
is a Ruby operator. This code is basically evaluating the expressioncurrent_user.location.path_ids || current_user.location.parent.descendant_ids
and passing that value as the second argument to thewith
method.Check out the Sunspot README. I think you need
any_of
:虽然我没有使用过Sunspot,但我想我能看出问题所在。
||
运算符是逻辑 OR,因此它返回左操作数,因为它的计算结果为 true。我假设
current_user.location.path_ids
和current_user.location.parent.descendant_ids
都是数组,因此您需要将它们与|
结合起来改为 code> 运算符。Although I haven't used Sunspot, I think I can see the problem.
The
||
operator is logical OR so it is returning the left operand because it evaluates true.I am assuming that
current_user.location.path_ids
andcurrent_user.location.parent.descendant_ids
are both arrays, therefore you will need to combine them with the|
operator instead.