在2个以上具有不同数据的表中进行全文搜索

发布于 2024-11-23 15:23:14 字数 1057 浏览 3 评论 0原文

你好,我有这个sql语句

SELECT *,  MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) AS score, MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE) AS sscore
FROM users INNER JOIN groups  
WHERE MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) OR MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE) 
 ORDER BY 'score' Desc 

1)我如何按联合分数排序?我的意思是,使用这个 sql 语句,它会为第一场比赛创建一个分数,并为第二场比赛创建一个分数。我如何将这两个分数相加并按该分数排序?

2)我也知道,由于数据不一样,INNER JOIN 方式不是最好的。我可以删除它吗?

最后,如果我在使用例如sim时删除IN BOOLEAN MODE并且first_name是simos,我不会得到结果。事实上,在布尔模式下,如果我输入 sim,我会得到一个空结果集,我将得到 simos 作为结果。

编辑:我通过做这个

(SELECT `id`,MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE) AS score FROM `users` WHERE MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE))

联盟 回答了我的第二个问题 (SELECT groupid, MATCH(groupname) AGAINST ('?') AS 分数 FROM groups WHERE MATCH(groupname) AGAINST ('?') )

这虽然改变了一切,因为我不需要联合分数,但仍然有布尔模式的问题

Hi I have this sql statement

SELECT *,  MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) AS score, MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE) AS sscore
FROM users INNER JOIN groups  
WHERE MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) OR MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE) 
 ORDER BY 'score' Desc 

1) How can I ORDER by the joint score? I mean with this sql statement, it creates a score for the first match and a score for the second. How can I add those two scores and order by that score?

2) Also I know since the data are not the same the INNER JOIN way is not the best. is there anyway I can remove it?

and lastly, if i remove IN BOOLEAN MODE when i use for example sim and the first_name is simos I don't get the result. In fact I get an empty result set while in boolean mode if I put sim I'll get the simos as result.

EDIT: I responded my 2nd question by doing this

(SELECT `id`,MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE) AS score FROM `users` WHERE MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE))

union
(SELECT groupid, MATCH(groupname) AGAINST ('?') AS score FROM groups WHERE MATCH(groupname) AGAINST ('?') )

This though changes everything though as I don't need a joint score but still have the problem with the IN BOOLEAN MODE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里兽 2024-11-30 15:23:14

order by 'score' 不正确,它将尝试按固定字符串 score' 进行排序,而不是您在 match 中创建的别名...反对。

尝试

...
ORDER BY (score + sscore) DESC

order by 'score' is incorrect, it'll be trying to order by a fixed string score', not the alias you created in the match ... against.

Try

...
ORDER BY (score + sscore) DESC
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文