Mysql Match Against&喜欢搜索

时间:2013-09-14 23:45:56

标签: php mysql

SELECT * FROM `db` 
WHERE MATCH (city) AGAINST ('south ban' IN BOOLEAN MODE)

SELECT * FROM 'db'
WHERE city LIKE '%south ban%'

我有2个查询,一个是使用匹配,另一个是LIKE,

当我尝试搜索“南岸”时

如果用户输入南禁止

Match将不会返回,但Like将返回结果

如何改善与搜索的匹配?

我做了测试,

(country LIKE '%south%' || state  LIKE '%south%' || city  LIKE '%south%') &&
(country LIKE '%bank%' || state  LIKE '%bank%' || city  LIKE '%bank%')

MATCH (country, stateprov, city) AGAINST ('south bank*' IN BOOLEAN MODE)

为3百万行

匹配 - 69,310行 - 2.5秒

LIKE - 67,092行 - 1.87秒

为什么比匹配更快?

1 个答案:

答案 0 :(得分:1)

如果你使用不带+的IN BOOLEAN MODE查询,匹配实际上是对每一行进行评级,这需要时间。

http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

查看此信息
(no operator)

By default (when neither + nor - is specified) the word is optional, but the rows that contain it are rated higher. This mimics the behavior of MATCH() ... AGAINST() without the IN BOOLEAN MODE modifier.