0
如何使用https://github.com/ankane/searchkick搜索Users
和Skills
,並返回搜索技能的用戶。最相關的結果應反映User
有多少個skills
。searchkick search HABTM
我的模型是這樣的:
class User < ApplicationRecord
searchkick
has_many :user_skills
has_many :skills, through: :user_skills
end
class Skill < ApplicationRecord
searchkick
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
searchkick
belongs_to :user
belongs_to :skill
end
我曾嘗試以下,但沒有結果返回:
@search = User.search "*", where: {
skill_ids: {all: [1, 3]}
}
@fbelanger我肯定知道,它應該返回結果。我發現https://github.com/ankane/searchkick是我需要的複雜方式。所以我改用https://github.com/activerecord-hackery/ransack代替 –