There are certain characters (operators) that affects behavior of full-text search in MariaDB. They are +-<>()~*" and their functionality is described in documentation.
I want to be able to search for a word which contains one of these operators and I want MariaDB to deal with it as a normal character not an operator. How can I do it?
Example:
Let's create table with full-text index:
CREATE TABLE users (username TEXT, FULLTEXT(username)) ENGINE=InnoDB;
INSERT INTO users(username) VALUES ('joseph'), ('jose'), ('jose*');
Now I want to search for rows which contains exactly jose*:
SELECT * FROM users WHERE MATCH(username) AGAINST('jose*' IN BOOLEAN MODE);
+----------+
| username |
+----------+
| joseph |
| jose |
| jose* |
+----------+
But I want only row with jose*. The same result is when I try to escape that string the way I would expect it could work.
SELECT * FROM users WHERE MATCH(username) AGAINST('jose\*' IN BOOLEAN MODE);
+----------+
| username |
+----------+
| joseph |
| jose |
| jose* |
+----------+
SELECT * FROM users WHERE MATCH(username) AGAINST('jose\\*' IN BOOLEAN MODE);
+----------+
| username |
+----------+
| joseph |
| jose |
| jose* |
+----------+
What is the proper way to escape string for full-text search in MariaDB/MySQL?