搜索电子邮件地址时遇到MySQL MATCH AGAINST [英] MySQL MATCH AGAINST when searching e-mail addresses

查看:146
本文介绍了搜索电子邮件地址时遇到MySQL MATCH AGAINST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写新闻稿脚本,我需要在地址中执行搜索。我使用FULLTEXT为表建立了索引,但是当我执行如下查询时:

  SELECT * FROM addresses WHERE MATCH(email)AGAINST name@example.com在BOOLEAN模式)

我得到了奇怪的结果。它显示example.com上的所有电子邮件以及所有具有用户名称的电子邮件。例如,我得到:

  john@example.com 
name@mail.net
steven @示例.com重新编写查询以使用LIKE%name@example.com%但是对于大表需要花费大量的时间才能完成。
是否有解决方案?我希望在搜索时只显示完整的匹配电子邮件,而不是其中的一部分。

解决方案

要匹配一个确切的短语,您必须将该短语用双引号引起来。因此,请将您的查询改为:



SELECT * FROM addresses WHERE MATCH(email)AGAINST(''name@example.com'''BOOLEAN MODE )



来源


I am writing a newsletter script and I need to implement searching in the addresses. I indexed the table with FULLTEXT but when I do a query such as:

SELECT * FROM addresses WHERE MATCH(email) AGAINST("name@example.com" IN BOOLEAN MODE)

I get strange results. It displays all emails on "example.com" and all emails with user "name". For example I get:

john@example.com
name@mail.net
steven@example.com

I rewrote the query to use LIKE "%name@example.com%" but for a big table it takes ridiculous amount of time to complete. Is there a solution for this? I want when searching to show only full matching emails and not part of them. Thank you in advance.

解决方案

To match an exact phrase you have to enclose the phrase in double quotes. So change your query to:

SELECT * FROM addresses WHERE MATCH(email) AGAINST('"name@example.com"' IN BOOLEAN MODE)

Source

这篇关于搜索电子邮件地址时遇到MySQL MATCH AGAINST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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