searchkick指数相关模型领域 [英] searchkick index related model fields

查看:218
本文介绍了searchkick指数相关模型领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个rails应用程序,我从Sphinx切换到ElasticSearch并使用gem searchkick。



我有一个模型老师和一个模型标签(通过一个宝石),教师可以有多个标签关联。在教师模型中,我定义了这样的索引:

  def search_data 
{
name:名字,
介绍:intro,
生物:生物,
标签名称:标签名称
}
结束
pre>

名称,简介和生物是教师属性,但是我想为与老师相关联的标签索引名称。我该怎么做?



现在的方式是索引对象的名称(关系),如何在标签对象内索引属性名称?

解决方案

在提出问题后不久,我找到了有关 github页面

  def search_data 
{
名称:
intro:intro,
bio:bio,
tag_name:tags.map(&:name)
}
end

索引正确的属性。


I have a rails application and I'm switching from Sphinx to ElasticSearch and using the gem searchkick.

I have a model Teacher and a model Tags (via a gem), where a Teacher can have multiple tags associated. In the Teacher model I've defined the index like this:

def search_data
    {
      name: name,
      intro: intro,
      bio: bio,
      tag_name: tags.name
    }
end

Name, intro and bio are Teacher attributes, but I want to index the name od the tags associeted to the teacher. How can I do this?

The way it is now, it indexes the name of the object (relation), how can I index the attribute name inside the tag object?

解决方案

Shortly after asking the question, I found a solution on one of the issues on the github page:

def search_data
    {
      name: name,
      intro: intro,
      bio: bio,
      tag_name: tags.map(&:name)
    }
end

That indexes the correct attributes.

这篇关于searchkick指数相关模型领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆