I have a wordpress plugin that essentially creates a mysql query and returns the results to wordpress.
It is user driven and so can end up in large queries with multiple NOT LIKEs which results in a very slow query.
Any suggestions that I could use to improve:
SELECT field1,field2,field3,field4
from datatable
WHERE (title NOT LIKE '%word%' AND title NOT LIKE '%word2%'
AND title NOT LIKE '%word3%' AND title NOT LIKE '%word4%'
AND title NOT LIKE '%word5%' AND title NOT LIKE '%word6%'
AND title NOT LIKE '%word7%' AND title NOT LIKE '%word8%'
AND title NOT LIKE '%word9%')
AND MATCH (title) AGAINST ("\"brandname\" " IN BOOLEAN MODE)
ORDER BY total ASC LIMIT 0,60
The customer is adding a lot of negative keywords to the wordpress plugin which results in larger queries than the one above.
This is most easily done with
REGEXP. For multiple words, use a group like(one|two|three)