简体   繁体   English

searchkick搜索HABTM

[英]searchkick search HABTM

How can I use https://github.com/ankane/searchkick to search both Users and Skills and return users with skills searched for. 如何使用https://github.com/ankane/searchkick来搜索“ Users和“ Skills并返回具有所搜索Skills用户。 Most relevant result should reflect how many of the skills the User has. 最相关的结果应反映User拥有多少skills

My Models look like this: 我的模型如下所示:

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

I have tried the following, but no result are returned: 我尝试了以下操作,但未返回任何结果:

@search = User.search "*", where: {
    skill_ids: {all: [1, 3]}
  }

Just because no results are returned, doesn't mean it is not working. 仅仅因为没有返回结果,并不意味着它不起作用。

Explain how this should return results in your question. 解释这应该如何返回结果。

@search = User.search "*", where: { skill_ids: [1, 3] }

Search Kick Queries: https://github.com/ankane/searchkick#queries 搜索踢查询: https : //github.com/ankane/searchkick#queries

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM