mysql匹配多个单词 [英] mysql match against multiple words

查看:134
本文介绍了mysql匹配多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个我坚持使用的示例sql,它不会返回名为iphone 4s的产品,它会返回10个其他结果。任何帮助将非常感谢

1st sql示例



  SELECT * FROM products 
WHERE match(desc)against('+ iphone + 4s'IN BOOLEAN MODE)LIMIT 10;

结果:包含单词'iphone'和'4s'



第二个sql示例



  SELECT * FROM products 
WHERE match(desc)against('+ iphone 4s'IN BOOLEAN MODE)LIMIT 10;

结果:包含单词'iphone',但是如果它们也包含'4s' / p>

第三个sql示例



  SELECT * FROM products 
WHERE match(desc)against('iphone 4s'IN BOOLEAN MODE)LIMIT 10;

结果:包含'iphone'或'4s'这两个字



我想要搜索的是'iphone 4s',但它带有其他结果,例如'iphone is good,but 4s ...','新iPhone 5已经发布...',...



任何人都可以帮我解决它吗?谢谢。

解决方案

为了匹配一个确切的短语,只需使用双引号括住短语以匹配;

<$

b

















更多信息在手册页面


Below is an example sql I am stuck with, it will not return a product named "iphone 4s", It returns 10 other result. Any help would be great thanks

1st sql example

SELECT * FROM products 
          WHERE match(desc) against('+iphone +4s' IN BOOLEAN MODE) LIMIT 10";

result: contains the words 'iphone' and '4s'

2nd sql example

SELECT * FROM products 
           WHERE match(desc) against('+iphone 4s' IN BOOLEAN MODE) LIMIT 10";

result: contains the words 'iphone', but rank rows higher if they also contain '4s'

3rd sql example

SELECT * FROM products 
           WHERE match(desc) against('iphone 4s' IN BOOLEAN MODE) LIMIT 10";

result: contains the words 'iphone' or '4s'

What I want to search is 'iphone 4s', but it comes with other result, like 'iphone is good, but 4s...', 'new iphone 5 has published...',...

Can anyone help me to solve it? thanks.

解决方案

To match an exact phrase, just use double quotes to surround the phrase to match;

SELECT * 
FROM products 
WHERE MATCH(desc) 
      AGAINST('"iphone 4s"' IN BOOLEAN MODE) 
LIMIT 10

More info at the manual pages.

这篇关于mysql匹配多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆