0
我正在開發一個使用rails 4的求職門戶。 我有搜索框,求職者可以在其中搜索工作。目前,我能夠做到這一點作業標題和說明,如下在rails 4中加入查詢
scope :by_name_or_desc,lambda{|search| where(" title ilike (?) or description ilike(?)","%#{search}%","%#{search}%") if search.present?}
我想使用相同的搜索框,技能也是在導引頭可以使用技能搜索工作。我的skill_ids作爲我的Job模型中的一列。這是數組字段。我如何修改上面的查詢來做同樣的事情。
我也試着這樣做,
scope :by_name_or_desc,lambda{|search| where(" title ilike (?) or description ilike(?) or '#{search}' = ANY (skill_ids)","%#{search}%","%#{search}%") if search.present?}
你可能會考慮尋找一個寶石來爲你做這種事情。例如pg_search - https://github.com/Casecommons/pg_search - 還有其他可用的。 –