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?
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
You can do the following in your migration
execute "CREATE FULLTEXT INDEX fulltext_name ON users (name)"
I would then suggest following this blog post about creating rake tasks and a schema.rb file that is compatible with this index type.
UPDATE: rigth link to blog post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With