Search Ruby On Rails

I have a small site with about 500 photos and 150 visitors per day, which is hosted on Dreamhost. I would like to add a simple search engine in which you do not need to run lengthy processes that are not allowed on the shared host.

The search engine must process various fields belonging to different models: Photo, Photo.author.name, Photo.comments.content and many others.

Is there any plugin that can help?

+4
source share
6 answers

MySQL's full-text search feature, which is usually available in any public hosting environment, is a great way to add this functionality. The only drawback is that it only works on MyISAM tables, which are usually outdated in favor of InnoDB.

The approach I saw works where a great example is the architecture of the Wikipedia database, which is to create derivative copies of model records specifically for search purposes. They need to be synchronized with the master record, but this is easy to do with the after_save handler or a simple SQL update statement.

It should be noted that ActiveRecord is not able to understand full-text indexes. To make it collaborate, a rather ugly extension is required, although I have an example compiled into the MySQL hacker collection:

http://github.com/theworkinggroup/rails_mysql_hacks/tree/master

+4
source

There are at least 3 full-text search engines for Rails:

Which one is the best choice? It depends. Here you can read the comparison between sphinx and horet, including a comment from Engine Yard.

+3
source

I think acts_as_indexed is the best choice for your needs. It does not require a separate server; it automatically creates its index in the file system. A site like yours was quick and easy to set up.

+2
source

acts_as_ferret will likely serve you well.

But I don’t know if and how Ferret will perform a setup similar to yours.

+1
source

Ferret or sphinx MUST use a dedicated background process. Your only option looks like a full-text mysql search with matching indexes.

+1
source

You can look in Sphinx / Thinking Sphinx for a quick full-text search.

Thinking sphinx

I don’t know if the installation of Unix packages and the whole process are overwhelmed with what you are looking for on Dreamhost, but it is a very fast and reliable solution that will satisfy your needs in the future.

0
source

Source: https://habr.com/ru/post/1286630/


All Articles