MySQL全文搜索不适用于电子邮件地址

I am using Laravel 5.5 & MySQL. I want to use full text search for emails but I keep getting this error:

Syntax error or access violation: 1064 syntax error, unexpected '@', expecting $end (SQL: select * from users where MATCH (users.email) AGAINST (+user@* IN BOOLEAN MODE) or MATCH (users.username) AGAINST (+user@* IN BOOLEAN MODE))

This is how I am querying

$keyword        = $request->keyword;
$exp            = explode(' ', $keyword);

$s = '';
$c = 1;
foreach ($exp AS $e)
{
    $s .= "+$e*";

    if ($c + 1 == count($exp))
        $s .= ' ';

    $c++;
}

$users = User::whereRaw("MATCH (users.email) AGAINST (? IN BOOLEAN MODE)", [$s])
            ->orWhereRaw("MATCH (users.username) AGAINST (? IN BOOLEAN MODE)", [$s])
            ->get();

I have tried changing the where clauses to escape and add quotes but its not working

::whereRaw('"MATCH (users.email) AGAINST (? IN BOOLEAN MODE)"', [$s])
->orWhereRaw('"MATCH (users.username) AGAINST (? IN BOOLEAN MODE)"', [$s])

::whereRaw("MATCH (users.email) AGAINST (? IN BOOLEAN MODE)", ["$s"])
->orWhereRaw("MATCH (users.username) AGAINST (? IN BOOLEAN MODE)", ["$s"])

::whereRaw('MATCH (users.email) AGAINST ("?" IN BOOLEAN MODE)', [$s])
->orWhereRaw('MATCH (users.username) AGAINST ("?" IN BOOLEAN MODE)', [$s])

This is a restriction in MySQL. From the documentation:

InnoDB full-text search does not support the use of the @ symbol in boolean full-text searches. The @ symbol is reserved for use by the @distance proximity search operator.

There was a bug report opened for this issue, but it was closed with the update to the documentation. This leads me to believe they don't consider it a bug, and this won't change any time soon.

You can try changing your table to the MyISAM engine. This is not ideal, and according to the mentioned bug report, still may not resolve the issue.

Unless you're stuffing multiple emails or usernames in your fields, I would assume you would be okay with using varchars, normal indexes, and LIKE queries. Since you seem to only be searching from the beginning of the string (e.g. email LIKE 'user@%'), a normal index would be used. You get in trouble when you need to place the wildcard at the start of the string.