如何在 Ruby on Rails 3 中使用 Active Record 搜索文本? [英] How to search for a text with Active Record in Ruby on Rails 3?

查看:45
本文介绍了如何在 Ruby on Rails 3 中使用 Active Record 搜索文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Ruby on Rails 中搜索字符串?

How do I search for a string in Ruby on Rails?

例如,列包含文本"的所有记录.

For example, all records with columns that contains "text".

Active Record 有没有针对它的方法,还是我必须使用 SQLLIKE"?

Does Active Record have a method for it or do I have to use SQL "LIKE" for it?

推荐答案

Sql like 在某些情况下可能效率很低,例如 在许多情况下在 MySQL 中.我建议使用一些全文索引软件,如 Sphinx、Xapian 或 Lucene.

Sql like may be very inefficient in some cases, for example in many cases in MySQL. I recommend using some full-text indexing software like Sphinx, Xapian or Lucene.

这篇关于如何在 Ruby on Rails 3 中使用 Active Record 搜索文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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