[英]How can I restrict the SELECT MATCH AGAINST to return ony results that contains all searched terms?
If I my term is for example iphone ipod the following query 如果我的术语是例如iphone ipod,则以下查询
SELECT id FROM products WHERE MATCH (name) AGAINST ('$term')
will give me results that contain both terms or only one of them. 会给我包含两个或两个术语的结果。
How can I restrict to show me only results that contain both terms? 如何限制显示仅包含两个术语的结果? Speed is my concern. 速度是我的关注点。
Thank you. 谢谢。
Add a +
before every word: 在每个单词前添加一个+
:
$words = explode(" ", $term);
$all = implode(" +",$words);
$sql =
"SELECT id
FROM products
WHERE MATCH (name) AGAINST ('+" . $all . "' IN BOOLEAN MODE)"
Be sure to escape the input terms to prevent SQL Injection. 确保转义输入项以防止SQL注入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.