如何在Ruby on Rails中进行全文搜索? [英] How do I do full-text searching in Ruby on Rails?

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

问题描述

我想在我的Ruby on Rails应用程序中对数据进行全文搜索。有什么选择?

解决方案

有几种选择可供选择,每种选择都有不同的优缺点。如果您想添加全文搜索,则谨慎调查每一项,并尝试一下,看看它在您的环境中对您的工作有多好。



< MySQL内置了对全文搜索的支持。它具有在线支持,这意味着将新记录添加到数据库时,它们会自动编入索引并在搜索结果中可用。 文档有更多详细信息。



acts_as_tsearch 为近期版本 PostgreSQL



对于其他数据库,您必须使用其他软件。

Lucene 是一种用Java编写的热门搜索提供程序。您可以使用 Solr 来使用Lucene acts-as-solr.rubyforge.org/rel =nofollow noreferrer> acts_as_solr



<如果你不想使用Java,那么有一个Lucene到Ruby的端口叫做 Ferret

一>。 Rails支持使用
acts_as_ferret 插件。



Xapian 是另一个不错的选择,它是Rails支持使用 acts_as_xapian 插件。



最后,我的首选是狮身人面像使用 Ultrasphinx 插件。它非常快速,并且有很多关于如何索引和搜索数据库的选项,但不再被主动维护。



另一个Sphinx插件是思考狮身人面像有很多积极的 feedback 。开始使用Thinking Sphinx比Ultrasphinx更容易一些。我会建议调查这两个插件,以确定哪个更适合您的项目。


I would like to do full-text searching of data in my Ruby on Rails application. What options exist?

解决方案

There are several options available and each have different strengths and weaknesses. If you would like to add full-text searching, it would be prudent to investigate each a little bit and try them out to see how well it works for you in your environment.

MySQL has built-in support for full-text searching. It has online support meaning that when new records are added to the database, they are automatically indexed and will be available in the search results. The documentation has more details.

acts_as_tsearch offers a wrapper for similar built-in functionality for recent versions of PostgreSQL

For other databases you will have to use other software.

Lucene is a popular search provider written in Java. You can use Lucene through its search server Solr with Rails using acts_as_solr.

If you don't want to use Java, there is a port of Lucene to Ruby called Ferret. Support for Rails is added using the acts_as_ferret plugin.

Xapian is another good option and is supported in Rails using the acts_as_xapian plugin.

Finally, my preferred choice is Sphinx using the Ultrasphinx plugin. It is extremely fast and has many options on how to index and search your databases, but is no longer being actively maintained.

Another plugin for Sphinx is Thinking Sphinx which has a lot of positive feedback. It is a little easier to get started using Thinking Sphinx than Ultrasphinx. I would suggest investigating both plugins to determine which fits better with your project.

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

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