Reputation: 2244
I'm trying to return results from a table of products when a user searches it by name. Currently I have this query (simplified):
SELECT id, name FROM products WHERE status > 0 AND MATCH(name) AGAINST('test druzy%' IN BOOLEAN MODE) ORDER BY id desc LIMIT 0, 50
Where my search query was test druzy
. These are the results I get.
The problem is that I don't want results 'Test Tie Necklace' for instance. Mysql is searching for test and druzy seperately. How do I search for both words combined. Performance is also a concern since the table is expected to be very large.
I tried using LIKE as well but that doesn't return any results at all.
Any ideas?
Upvotes: 1
Views: 227
Reputation: 64496
To search for both words you could use +
operator like
MATCH(name) AGAINST('+test +druzy' IN BOOLEAN MODE)
Upvotes: 1
Reputation: 872
Have you tried lower the field name and apply LIKE like this :
SELECT id, name
FROM products
WHERE status > 0
AND LOWER(name) LIKE LOWER('Test Druzy%')
ORDER BY id desc LIMIT 0, 50
EDIT : You can put LOWER at the other side Or use a charset format case-insensitive
Upvotes: 0