2010-12-21 50 views
1

语法正在杀死我!接下来的查询有问题:在MySQL查询和全文中的Concat()

$cadbusca="SELECT * , MATCH (nombre, apellido, email, about, place, CONCAT(nombre,' ',apellido)) AGAINST ('$busqueda') AS Score FROM user WHERE MATCH (nombre, apellido, email, about, place, CONCAT(nombre,' ',apellido)) AGAINST ('$busqueda') ORDER BY Score DESC"; 

错误:

Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(nombre,' ',apellido)) AGAINST ('dan stern') AS Score FROM user WHERE MATCH (nom' at line 1.

“丹严厉”是词搜索...

+0

我真的不能告诉什么,但我认为这是在u使用比赛和反对,因此 – Tebo 2010-12-21 21:40:22

回答

2

要执行使用MATCH/AGAINST一个全文搜索,必须在要搜索的字段上有全文索引。见match/against doc

话虽如此,你正试图在你的MATCH中包含一个动态实体CONCAT(nombre,' ',apellido),这是不允许的 - 你不能在这样的动态字段上有索引。

Full-Text Restrictions doc

The MATCH() column list must match exactly the column list in some FULLTEXT index definition for the table, unless this MATCH() is IN BOOLEAN MODE. Boolean-mode searches can be done on nonindexed columns, although they are likely to be slow.

+0

来连接两个colums只有这样的办法就是让一个布尔modea搜索? – 2010-12-21 22:00:16

+0

不 - 你显然甚至不能这么做。贾斯汀建议创建一个你想要的连接的列是一个好方法,如果可以的话。或者,您是否考虑过仅使用带有通配符的LIKE运算符? - http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like – Riedsio 2010-12-21 22:05:25