我需要使用公共密钥从多个表中获取MATCH AGAINST分数并合并它们的总和。最终的目标是创建一个搜索算法,该算法将返回具有匹配的group_ID的行。我已经构建了一个尚无错误运行的mysql查询。
如果你想知道,这是具体的错误:
警告:mysql_fetch_array():提供的参数不是有效的MySQL 结果资源
这些是我想搜索的表格:
group_ID,名称
chat_ID,group_ID,name
event_ID,group_ID,title,description
我当前的查询如下所示:
SELECT
g.group_ID AS group_ID,
g.name AS name,
SUM(gscore + cscore + escore) AS score,
MATCH(g.name) AGAINST (" . $query . "') AS gscore,
MATCH(c.name) AGAINST (" . $query . "') AS cscore,
MATCH(e.title,e.description) AGAINST (" . $query . "') AS escore
FROM jn_groups g
LEFT JOIN jn_chat c ON g.group_ID = c.group_ID
LEFT JOIN jn_events e ON g.group_ID = e.group_ID
WHERE
MATCH(g.name) AGAINST (" . $query . "')
OR MATCH(c.name) AGAINST (" . $query . "')
OR MATCH(e.title,e.description) AGAINST (" . $query . "')
ORDER BY score
任何帮助提出类似于该运行的查询都将非常感激!
答案 0 :(得分:2)
可能是打破此查询的两件事:
变量$query
您的所有AGAINST运算符都以 "'
结尾,但仅从 "
开始。确保$query
包含
'
开始。汇总部分结果
您的SUM
无效,因为它不知道gscore
,cscore
和escore
。它将寻找字段名称。您可以更改此语句的这一部分(ofc将 hello world
替换为您想要的搜索字词):
....
SUM(
(MATCH(g.name) AGAINST ('hello world'))
+ (MATCH(c.name) AGAINST ('hello world'))
+ (MATCH(e.title,e.description) AGAINST ('hello world'))
) AS score,
....
两个建议:
NAME
等保留变量时要小心。要么正确地逃避它们,要么 - 在我看来更好 - 避免它们。