Mysql – full-text thesql search in rails

full-text-searchMySQLruby-on-rails

I'm trying to add a simple mysql full-text search to a small table <2000 entries.

Please don't tell me to install solr, or any other search gems. I've tried to run them and it seems to be one issue after another. I'll get around to it one day, but that day is not today.

I need to add an add_index migration, but when I run

add_index :users, :name, :fulltext

I get an error. – undefinded method 'key'.

I can't seem to find any documentation anywhere which explains how to make a fulltext mysql search in rails.

What is the correct statement I'm supposed to use for the add_index, and once that is done, do I have to anything special in my model to use the fulltext search?

Best Answer

Maybe an late answer but someone else might search for this like I just did.

This worked for me.

add_index :users, :name, name: 'name', type: :fulltext

Or for multiply columns

add_index :users, [:name, :description], name: 'name_description', type: :fulltext