0

How can I use https://github.com/ankane/searchkick to search both Users and Skills and return users with skills searched for. Most relevant result should reflect how many of the skills the User has.

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]}
  }
Hasmukh Rathod
  • 1,108
  • 1
  • 14
  • 20
  • @fbelanger I know for sure that it should return results. I found that https://github.com/ankane/searchkick was way to complex for my needs. So I have switched to https://github.com/activerecord-hackery/ransack instead – Kasper Andkjaer Aug 26 '16 at 09:49

1 Answers1

0

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

fbelanger
  • 3,522
  • 1
  • 17
  • 32