我有一个(mysql-)表,包含两列-->firstname,middlename的全文索引。
当我使用sql时

SELECT firstname, middlename, MATCH (firstname, middlename) as score AGAINST ('Peter') FROM database.tbl_names where MATCH (firstname, middlename) AGAINST ('Peter')

我得到3列-->名字、中间名和分数。
但是当我用红宝石做的时候
TblName.find(:all, :select => "firstname, middlename, match(firstname, middlename) against ('Peter')as score", :order => 'score desc', :conditions => ['match(firstname, middlename) against (?)', 'Peter'], :limit => 20)

我只得到一个有两个“列”但没有“匹配列”的数组
<TblName firstname: "Peter", middlename: "">

我搜索了一整个星期天,没有找到数组中“匹配列”的解决方案。
有人能帮我吗?
谢谢你!!!

最佳答案

Rails 4版本:

Model.select("*, MATCH(title) AGAINST ('keyword') AS score").where("MATCH(title) AGAINST('keyword')").reorder("score DESC").first.score

关于mysql - ruby on rails mysql全文相关分数在数组中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24853844/

10-13 09:49