MySQL MATCH AGAINST when searching e-mail addresses

前端 未结 2 1557
慢半拍i
慢半拍i 2021-01-06 20:40

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          


        
相关标签:
2条回答
  • 2021-01-06 21:04

    You can use a traditional index (with a simple = operator) instead of a fulltext index. It will work fast and use less resource on DB engine.

    SELECT * FROM addresses WHERE email = 'name@example.com';
    

    In this case, it is also possible to use a like operator, with % at the end of search string if you want to find by initial part of email address.

    SELECT * FROM addresses WHERE email like 'name@exam%';
     
    
    0 讨论(0)
  • 2021-01-06 21:11

    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

    0 讨论(0)
提交回复
热议问题