0

太陽黒点検索で「または」を使用するにはどうすればよいですか?

私のコードでは

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)

私の質問を理解していただければ幸いです。

4

2 に答える 2

2

||は Ruby のオペレーターです。このコードは基本的に式current_user.location.path_ids || current_user.location.parent.descendant_idsを評価し、その値を 2 番目の引数としてメソッドに渡しますwith

Sunspot READMEを確認してください。私はあなたが必要だと思いますany_of

any_of do
  with(:location_id, current_user.location.path_ids)
  with(:location_id, current_user.location.parent.descendant_ids)
end
于 2012-02-05T14:13:59.670 に答える