How to use a full text index for exact matches?

一笑奈何 提交于 2019-12-05 14:53:11
Sudhir Bastakoti

Something like this:

SELECT id 
  FROM tblsearch 
 WHERE MATCH (title, brand) AGAINST ("exact phrase") 
   AND CONCAT(title, ' ', brand) LIKE '%exact phrase%';

Hope it helps

If you need to find the exact title or brand, you need to use the equal operator with a classical index :

ALTER TABLE tblsearch ADD INDEX search_idx(title, brand);
SELECT id FROM tblsearch WHERE title = 'foo' AND brand = 'bar';

Now if you just need to match exact words into the title and brand:

SELECT id FROM tblsearch WHERE
MATCH(title) AGAINST('+foo' IN BOOLEAN MODE)
AND MATCH(brand) AGAINST('+bar' IN BOOLEAN MODE);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!