How do I do full-text searching in Ruby on Rails?

前端 未结 8 1940
忘了有多久
忘了有多久 2020-12-02 19:39

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

8条回答
  •  醉梦人生
    2020-12-02 20:06

    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.

提交回复
热议问题