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.
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_idsandcurrent_user.location.parent.descendant_idsare both arrays, therefore you will need to combine them with the|operator instead.