Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL+;Rails按找到的关键字计数排序_Mysql_Ruby On Rails_Ruby_Innodb - Fatal编程技术网

MySQL+;Rails按找到的关键字计数排序

MySQL+;Rails按找到的关键字计数排序,mysql,ruby-on-rails,ruby,innodb,Mysql,Ruby On Rails,Ruby,Innodb,我在MySQL/InnoDB中有一个Faq类,它的实例关键字如下 apple,juice,fruit 我有一个课堂方法 def self.find_by_string string = nil unless string.present? return end keywords = string.gsub(/(\,|\.|\s)/, " ").split.uniq.join("|") Faq.find( :all, :conditio

我在MySQL/InnoDB中有一个Faq类,它的实例关键字如下

apple,juice,fruit
我有一个课堂方法

def self.find_by_string string = nil
 unless string.present?
   return
 end

 keywords = string.gsub(/(\,|\.|\s)/, " ").split.uniq.join("|")

 Faq.find(
          :all, 
          :conditions => "keywords like '%" + keywords.gsub(/\|/, "%' or keywords like '%") + "%'"
        )
end

我需要排序的结果,找到的关键字在它的计数查找。我的意思是,如果SQL发现了4个关键字,那么结果一定比3个关键字高。怎么做?

你可以跳过一步,把一个参数传递给
split
,把它简化为
string.split(/(\,\124;\。\ s)/,”)
,而不是执行
string.gsub(/(\,|\。\124;\ s)]
我认识这个人,但我这么做有一个特别的功能,这并不重要。但是谢谢。