searchkick搜索HABTM

时间:2016-08-25 10:02:50

标签: ruby-on-rails search has-and-belongs-to-many searchkick

如何使用https://github.com/ankane/searchkick搜索UsersSkills并返回具有搜索技能的用户。最相关的结果应反映skills User中有多少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]}
  }

我已尝试过以下操作,但未返回任何结果:

var builder = new AlertDialog.Builder (this);
...
...
...
var dialog = builder.Show ();
int textColorId = Resources.GetIdentifier ("alertTitle", "id", "android");
TextView textColor = dialog.FindViewById<TextView> (textColorId);
textColor?.SetTextColor (Color.DarkRed);

1 个答案:

答案 0 :(得分:0)

仅仅因为没有返回结果,并不意味着它不起作用。

解释这应该如何在您的问题中返回结果。

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

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