How to use prefix wildcards like '*abc' with match-against

前端 未结 2 590
悲哀的现实
悲哀的现实 2021-01-21 08:06

I have the following query :

SELECT * FROM `user` 
WHERE MATCH (user_login) AGAINST (\'supriya*\' IN BOOLEAN MODE)

Which outputs all the record

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 08:53

    Match doesn't work with starting wildcards, so matching with *abc* won't work. You will have to use LIKE to achieve this:

    SELECT * FROM user WHERE user_login LIKE '%abc';
    

    This will be very slow however.

    If you really need to match for the ending of the string, and you have to do this often while the performance is killing you, a solution would be to create a separate column in which you reverse the strings, so you got:

    user_login user_login_rev
    xyzabc     cbazyx
    

    Then, instead of looking for '%abc', you can look for 'cba%' which is much faster if the column is indexed. And you can again use MATCH if you like to search for 'cba*'. You will just have to reverse the search string as well.

提交回复
热议问题