如何使用全文索引进行精确匹配? [英] How to use a full text index for exact matches?
本文介绍了如何使用全文索引进行精确匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有全文索引的MySql MyISAM表,如下所示:
I have a MySql MyISAM table with a full text index, like this:
CREATE TABLE `tblsearch` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`brand` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `index_all` (`title`,`brand`)
) ENGINE=MyISAM AUTO_INCREMENT=1316109 DEFAULT CHARSET=utf8;
现在我需要编写一个像这样的查询来查找具有确切名称和品牌的所有条目:
Now I need to write a query like this to find all entries with the exact title and brand:
SELECT id FROM tblsearch WHERE title=?title AND brand=?brand;
查询只给出完全匹配是很重要的。我希望能够使用我已有的全文索引。是否有可能编写查询,以便使用全文索引?
It is important that the query only give exact matches. I would like to be able to use the full text index that I already have. Is it possible to write the query so it uses the full text index?
推荐答案
类似这样:
SELECT id
FROM tblsearch
WHERE MATCH (title, brand) AGAINST ("exact phrase")
AND CONCAT(title, ' ', brand) LIKE '%exact phrase%';
希望它有帮助
这篇关于如何使用全文索引进行精确匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文