Mysql – MariaDB FULLTEXT search with apostrophe, and mandatory words

full-text-searchmariadbMySQLselect

An apostrophe / single quote (') should be part of a word in a FULLTEXT index.

Admittedly I can't find this on the MariaDB website, but I'm assuming it should still behave like MySQL (version 5.5).

But when using "IN BOOLEAN MODE", and prefixing the word with a "+" (so it's mandatory in all rows returned), the record is not returned.

For example:

CREATE TABLE customer (
    name TINYTEXT NOT NULL,
    FULLTEXT (name)
) ENGINE = InnoDB;

INSERT INTO customer VALUES ('O''Brien');
INSERT INTO customer VALUES ('O Brien');
INSERT INTO customer VALUES ('X''Brien');
INSERT INTO customer VALUES ('Extra Amy');
INSERT INTO customer VALUES ('Extra Brian');
INSERT INTO customer VALUES ('Extra Cat');
INSERT INTO customer VALUES ('Extra Debbie');

I get these results:

SELECT * FROM customer WHERE MATCH (name) AGAINST ("O'Brien" IN BOOLEAN MODE);
  "O'Brien"
  "O Brien"
  "X'Brien"
3 rows in set (0.000 sec)

SELECT * FROM customer WHERE MATCH (name) AGAINST ("+O'Brien" IN BOOLEAN MODE);
Empty set (0.000 sec)

SELECT * FROM customer WHERE MATCH (name) AGAINST ("+Brien" IN BOOLEAN MODE);
  "O'Brien"
  "O Brien"
  "X'Brien"
3 rows in set (0.000 sec)

SELECT * FROM customer WHERE MATCH (name) AGAINST (+"O'Brien" IN BOOLEAN MODE);
  "O'Brien"
  "O Brien"
  "X'Brien"
3 rows in set (0.000 sec)

Am I missing something, like needing to quote the apostrophe?

Or is this an intentional difference between InnoDB and MyISAM?


Thanks to @rick-james, I've updated this question to include 3 "extra" records to avoid the 50% threshold limit, and I've included an example where the + is before the quoted word.

Best Answer

If we create the table with the Aria or MyISAM storage engine, then the query succeeds:

CREATE TABLE customer2 (
    name TINYTEXT NOT NULL,
    FULLTEXT (name)
) ENGINE = Aria;

INSERT INTO customer2 VALUES ('O''Brien');

SELECT * FROM customer2 WHERE MATCH (name) AGAINST ("+O'Brien" IN BOOLEAN MODE);
1 row in set (0.001 sec)

CREATE TABLE customer3 (
    name TINYTEXT NOT NULL,
    FULLTEXT (name)
) ENGINE = MyISAM;

INSERT INTO customer3 VALUES ('O''Brien');

SELECT * FROM customer3 WHERE MATCH (name) AGAINST ("+O'Brien" IN BOOLEAN MODE);
1 row in set (0.001 sec)

However, InnoDB doesn't seem to work for me either (MariaDB 10.4.8.)

So that leads me to think this is a bug. I reported the issue here: https://jira.mariadb.org/browse/MDEV-20797