A full text search (FTS) will greatly improve the speed IMAP search commands. In particular, the Android GMail client will be able to search your inbox with lightning speed. This solution is lightweight and easy enough to set up. I’m assuming you have a working dovecot install at this point.
First, install the dovecot-lucene plugin. Unlike Solr, this won’t install any bloat such as tomcat or java.
sudo apt install dovecot-lucene
Then enable the plugin by adding it to
/etc/dovecot/conf.d/10-mail.conf. Uncomment the
mail_plugins line, and change it to:
mail_plugins = fts fts_lucene
/etc/dovecot/conf.d/90-plugin.conf to configure the plugin:
#setting_name = value
fts = lucene
fts_lucene = whitespace_chars=@. normalize no_snowball
Restart the dovecot service to apply all of the changes:
sudo service dovecot restart
To start indexing mail, run the following command as root:
# doveadm -v index -u '*' '*'
The base guide I used is here, but I’ve adapted it for Ubuntu.