全文mysql在rails中搜索 [英] full-text mysql search in rails

查看:61
本文介绍了全文mysql在rails中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个简单的mysql全文搜索添加到一个小表<2000条目。



请不要告诉我安装solr或任何其他搜索宝石。我试图运行它们,似乎是一个接一个的问题。有一天我会接受它,但那一天不是今天。



我需要添加一个add_index迁移,但是当我运行时


$ b add_index :users,:name,:fulltext

我得到一个错误。 - 未找到方法'钥匙'。



我无法在任何地方找到解释如何在rails中进行全文搜索的文档。



什么是我应该用于add_index的正确声明,并且一旦完成,是否必须在我的模型中使用全文搜索的特殊功能?

解决方案

也许是一个迟到的答案,但其他人可能会像我刚刚那样搜索这个。



这对我有用。

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

或用于乘积列

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


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

这篇关于全文mysql在rails中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆