![](/img/trans.png)
[英]Rails 4 - Thinking-Sphinx, search with condition in join table
[英]Thinking sphinx condition in HAS
我有一個索引,我想根據某些條件對某些屬性進行過濾。
下面的結構運行正常
Class A
attr_accessible :vaild_date
belongs_to: B
define_index 'index_for_a' do
indexes ...
...
has B.C.plant_id, :as => :plant_id
end
end
class B
has_many: C
end
class C
attr_accessible :plant_id,:month_timestamps
end
現在我的C類有很多行。 我只想為其中的行設置plant_id
C.month_timestamps = A.valid_date
請提出一些實現此目標的方法。 對於think_sphinx來說是新手,我無法正確使用條件和子句。
添加一個
#Assuming Class C is stored in db as Cs
where "Cs.month_timestamps = valid_date"
這樣到您的define_index
塊
define_index 'index_for_a' do
indexes ...
...
has B.C.plant_id, :as => :plant_id
join B.C
#Assuming Class C is stored in db as Cs
where "Cs.month_timestamps = valid_date"
end
更新
通過CrazyDiv建議的編輯更新了答案
更新
試試這個
has "IFNULL(Cs.plant_id,0)", :as => :plant_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.