简体   繁体   English

与Searchlogic关联

[英]Association with Searchlogic

Hi I have a post model that :has_many :reply, when using searchlogic, doing Post.reply_content_like("search"), returns a result for every reply under that post, I only want it to return once. 嗨,我有一个帖子模型::has_many:reply,当使用searchlogic时,执行Post.reply_content_like(“ search”),为该帖子下的每个回复都返回一个结果,我只希望它返回一次。 Anyone know a way to solve this 任何人都知道解决此问题的方法

Searchlogic returns an array of Posts matching your criteria, just as if you used an ActiveRecord find . Searchlogic返回符合您条件的帖子数组,就像您使用ActiveRecord find If you only want to get one result, well, which one? 如果您只想得到一个结果,那么,哪个? The first? 首先? The last? 最后?

If you want to get the unique, matched column values, you could do 如果要获取唯一的,匹配的列值,则可以执行

Post.reply_content_like("search").collect(&:reply_content).uniq

or if you just want the first Post 或者,如果您只想要第一篇文章

Post.reply_content_like("search").first

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM