Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search in 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 that does not need to run long time processes which are not allowed on shared host.

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

Is there any plugin that can help?

like image 804
collimarco Avatar asked Dec 23 '22 10:12

collimarco


1 Answers

The full-text search feature of MySQL, which is generally available on any shared hosting environment, is a great way to add this kind of functionality. The only downside is that it works only on MyISAM tables which have generally been deprecated in favor of InnoDB.

The approach that I have seen work, where a great example is the Wikipedia database architecture, is to create derivative copies of model records specifically for searching purposes. These need to be kept in sync with the main record, but that's easily done with an after_save handler or a simple SQL update statement.

One note is that ActiveRecord is not capable of understanding full-text indexes. A rather ugly extension is required to make it cooperate, though I do have an example bundled up in a collection of MySQL hacks:

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

like image 122
tadman Avatar answered Jan 14 '23 07:01

tadman