searchkick指数相关模型领域

编程入门 行业动态 更新时间:2024-10-23 19:33:52
本文介绍了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指数相关模型领域

本文发布于:2023-11-25 13:53:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630020.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   指数   领域   searchkick

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!