Full-text mysql search in rails

I am trying to add a simple mysql text search to a small table <2000 records.

Please do not tell me to install solr or any other search stones. I tried to run them, and this seems to be one problem after another. One day I will come to him, but today is not this day.

I need to add add_index migration, but when I started

  add_index: users,: name,: fulltext

I get an error message. is the key of the indefinite method.

I cannot find any documentation anywhere that explains how to do mysql full-text search in rails.

What is the correct operator that I should use for add_index, and once this is done, do I need something special in my model in order to use full-text search?

+4
source share
2 answers

Maybe a late answer, but someone else might find this, as I just did.

It worked for me.

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

Or to multiply columns

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

You can do the following in your migration

 execute "CREATE FULLTEXT INDEX fulltext_name ON users (name)" 

I would suggest the following this blog post about creating rake tasks and a schema.rb file that is compatible with this type of index.

UPDATE: strong link to blog post

+1
source

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


All Articles