Enabling 3-letter word searches in mediawiki

Mediawiki uses MySQL’s full-text searching capabilities for its searching.  I’ve always been irritated that I can’t search for a three-letter word, like “nfs”.  It turns out that this is due to a default configuration in MySQL.  In this article, I’ll try to pull together various tips I’ve seen around the Web for enabling searches for 3-letter words.

For performance reasons, MySQL doesn’t index words smaller than 4 letters.  I can see that this would be a problem with massive databases that receive lots of updates and searches.  But we use Mediawiki as an intranet tool.  It probably gets under 1,000 pageviews per day.  I’ll take the performance hit in exchange for the convenience.

I found a number of partially-correct blog posts on how to change this specifically for Mediawiki, assembled the correct parts, and present the full step-by-step (for Linux systems, natch) here.

1. Configure MySQL to index words smaller than 4 letters.  Edit /etc/my.cnf, adding the ft_min_word_len directive in the [mysqld] and [mysqld_safe] sections.

2. Save your changes and restart the mysqld service.

3. Rebuild the indexes on your tables.  Use mysqlcheck to do this
(substitute your mediawiki database name for DBNAME)

4. from your wiki directory, run this command:
On this last step, you may run into permissions issues.  By default, the MySQL user that mediawiki uses did not have the “Lock tables” privilege.  If you need to add this, just do the following:

Leave a Reply

Your email address will not be published. Required fields are marked *