mysql查询和全文中的Concat()

发布于 2024-10-08 20:12:39 字数 560 浏览 8 评论 0原文

语法快要死我了!下一个查询有问题:

$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";

错误:

查询失败:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '(nombre,' ',apellido)) AGAINST ('dan stern') AS Score FROM user WHERE MATCH (nom' 附近使用的正确语法在第 1 行。

“dan stern” 是搜索的词...

The syntax is killing me! the next query is having problems:

$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";

Error:

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.

"dan stern" are the words searched...

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

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

发布评论

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

评论(2

┊风居住的梦幻卍 2024-10-15 20:12:39

要使用 MATCH/AGAINST 执行全文搜索,您必须在要搜索的字段上有全文索引。请参阅匹配/针对文档

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

来自全文限制文档

MATCH() 列列表必须匹配
正是某些中的列列表
FULLTEXT 索引定义为
表,除非此 MATCH() 为 IN
布尔模式。布尔模式搜索
可以在非索引列上完成,
尽管它们可能会很慢。

To perform a fulltext search using MATCH/AGAINST, you must have a full-text index on the fields you want to do the search on. See match/against doc.

Having said that, you're trying to include a dynamic entity, CONCAT(nombre,' ',apellido), in your MATCH, which is not allowed -- you can't have an index on a dynamic field like that.

From the 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.

痕至 2024-10-15 20:12:39

您需要创建一个类似于您想要的 concat 命令的列并对其进行索引。 (正如 Riedsio 所指出的)。另外,如果您的 where 子句中有匹配项,则无需执行“ORDER BY”,因为它会自动为您排序。

http:// www.devarticles.com/c/a/MySQL/Getting-Started-With-MySQLs-Full-Text-Search-Capability/2/

You'll need to create a column which is like the concat command you want and index against it. (As noted by Riedsio). Also, if you have the match in your where clause you don't need to do an 'ORDER BY' since it automatically sorts it for you.

http://www.devarticles.com/c/a/MySQL/Getting-Started-With-MySQLs-Full-Text-Search-Capabilities/2/

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