我有一个模型老师和一个模型标签(通过一个宝石),教师可以有多个标签关联。在教师模型中,我定义了这样的索引:
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 } endName, 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) } endThat indexes the correct attributes.
更多推荐
searchkick指数相关模型领域
发布评论