[英]Space in MySQL search
My query is formulated thus: 我的查询是这样写的:
$sql = "SELECT name, id FROM table WHERE MATCH (name) AGAINST ('".$query."*' IN BOOLEAN MODE) LIMIT 0,10";
So searching for tom
retrieves: 因此,搜索tom
检索:
Tom Anderson | 1
Tom Bennet | 2
Tom Cane | 3
However, if I search for tom anderson
the query compiles to: 但是,如果我搜索tom anderson
,查询将编译为:
...MATCH (name) AGAINST ('tom anderson*' IN BOOLEAN MODE)...
Which returns the same set of results (I only want the first). 它返回相同的结果集(我只想要第一个)。 How should I change my query? 我应该如何更改查询?
You should either use a +
to indicate a word must be present, or use "
to indicate a complete frase 您应使用+
表示必须出现一个单词,或使用"
表示完整的片段
Check the boolean mode manual 检查布尔模式手册
I guess this'll work 我想这会工作
...MATCH (name) AGAINST ('"tom anderson"*' IN BOOLEAN MODE)...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.