If I my term is for example iphone ipod the following query
SELECT id FROM products WHERE MATCH (name) AGAINST ('$term')
will give me results that contai开发者_如何转开发n 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)"
Documentation
Be sure to escape the input terms to prevent SQL Injection.
精彩评论