我正在尝试将mysql查询搜索重现为Rails(AR)模型代码。我在互联网上尝试了多个帖子,但没有一个适合我。
这是mysql查询:
SELECT id, title, content, created_at, match(title) against ('alpha' in natural language mode) AS score FROM users.hubspot_blog_posts
where match(title) against ('alpha' in natural language mode) order by score desc, created_at desc;
[想法是获取所有与搜索模式匹配的标题,并按得分排序,然后按created_at日期排序(如果得分相等)。(>
虽然上面的查询似乎可以按我的要求工作,但我无法将其转换为Rails代码。这是我尝试过的,得到相同的集合但不同的oredre:
HubspotBlogPost.select("*, MATCH(title) AGAINST ('alpha' in natural language mode) AS score").where("MATCH(title) AGAINST('alpha' in natural language mode)", :order => "score desc, created_at desc")
对于Mysql,如果score
相同,则按日期(created_at)进行排序,但红宝石代码无关紧要。
请纠正我,如果可能的话,让我知道我在哪里错了?
我正在尝试将mysql查询搜索重现为Rails(AR)模型代码。我在互联网上尝试了几篇文章,但没有一篇对我有用。这是mysql查询:SELECT id,title,content,...
订购者不是where()
的选项,它本身就是一种方法。