0
我有一個公司模型,有許多行業和一個級別。鐵路和solr如何限制或設置可搜索的屬性ID範圍
我有一個幫助功能,可以根據關卡獲取行業數量。
說一個具有「基本」級別的公司模型實例只能在前兩個行業中搜索,儘管它可能包含更多,但我只希望它顯示在前兩個行業的結果中。
在模型中我有
searchable do
integer :industry_ids, multiple: true
如何限制對模型實例的搜索,這樣可以搜索基於由num_of_industries輔助函數確定的水平只有行業的具體數量。
像
searchable do
integer :industry_ids[num_of_industries], multiple: true
編輯: 我想通了
LIMITED_INDUSTRIES_BASED_ON_LEVEL = {
'Free' => 1,
'Silver' => 3,
'Gold' => 5,
'Platinum' => 5
}
def industries_limited
self.industries.limit(LIMITED_INDUSTRIES_BASED_ON_LEVEL[self.level])
end
searchable do
integer :industry_ids, multiple: true do
self.industries_limited.map(&:id)
end
end
您談論公司,水平,像我們知道你的要求的行業。請添加相關細節,因爲我們無法承擔。請提供更高層次的問題概述以及相關問題的模式。 – aitchnyu
對不起,我不是很清楚,我明白了。 – gt565k