1

If I index the terms Maya Angelou and May Angelou (using MySQL's ngram fulltext index parser) and then search for the term may, the two items get the exact same score. Is there a way to optimize it so that May Angelou comes up first?

See:

CREATE TABLE test(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200)
);

ALTER TABLE test ADD FULLTEXT INDEX `test_fulltext_index`(title) WITH PARSER ngram;

insert into test(title) values('Maya Angelou');
insert into test(title) values('May Angelou');


SELECT title, MATCH(title) AGAINST ('may') as SCORE FROM test WHERE MATCH(title) AGAINST ('may');

This results in:

+--------------+----------------------------+
| title        | SCORE                      |
+--------------+----------------------------+
| Maya Angelou | 0.000000003771856604828372 |
| May Angelou  | 0.000000003771856604828372 |
+--------------+----------------------------+

Of course, using a normal FULLTEXT index (without the ngram parser) gives the following:

+-------------+--------------------+
| title       | SCORE              |
+-------------+--------------------+
| May Angelou | 0.0906190574169159 |
+-------------+--------------------+

I thought of having two indexes: one a normal FULLTEXT index and the other one using WITH PARSER ngram and then combining the results, but this doesn't seem to be possible.

How could this be done?

chintogtokh
  • 803
  • 1
  • 10
  • 25
  • Have you tried fulltext search with boolean mode? – Shadow Feb 12 '18 at 03:04
  • Yes, a boolean mode search results in the same score as well: `SELECT title, MATCH(title) AGAINST ('may*' IN BOOLEAN MODE) as SCORE FROM test WHERE MATCH(title) AGAINST ('may*' IN BOOLEAN MODE);` results in `Maya Angelou | 0.000000001885928302414186` and `May Angelou | 0.000000001885928302414186` – chintogtokh Feb 12 '18 at 03:08
  • Had the same problem, check out this answer https://stackoverflow.com/questions/37711370/mysql-how-to-get-search-results-with-accurate-relevance/49004865#answer-49004865 – friek108 Feb 27 '18 at 09:09

0 Answers0