I am trying to do a FULLTEXT search against two columns. The first column holds subject names, the second column aliases, such as:
| name | also_match |
-----------------------------------------------------
| Information Technology | IT I.T. |
| Mathematics | |
| English | |
| Religious Studies | RS R.S. RE R.E. |
Schema details:
These columns are both VARCHAR(100) and I have tried multiple types of FULLTEXT indexes. I have tried separate indexes for both of the columns, and I’ve tried an index that covers both columns together.
The search works fine at returning results based on the name column, but nothing turns up from the also_match column.
Example query that returns 1 result:
SELECT *
FROM subjects
WHERE MATCH(s.name, s.also_match) AGAINST ('*Information*' IN BOOLEAN MODE)
LIMIT 20
Example query that returns 0 results:
SELECT *
FROM subjects
WHERE MATCH(s.name, s.also_match) AGAINST ('*IT*' IN BOOLEAN MODE)
LIMIT 20
I think your problem is that MySQL does not index words shorter than a certain length. That length is specified in the ft_min_word_len variable.
For example, assuming your table is this:
Then the following query works:
If you make
ft_min_word_lenshorter, then it unfortunately affects the entire server, and is likely to make FULLTEXT indexes much larger.You might have to resort to using LIKE on also_match when you detect really short keywords, or build your own fulltext search.
One of these fulltext search engines might also be able to solve your problem: