I am using my own e-mail server for a few years now, but I almost never use search in my mailbox, so I did not really noticed how slow it was. All because the heavy lifting is left to the client to do.
Enter the FTS aka full-text search, a wonderful solution that forces server to do the dirty part, so your phone has more juice for browsing reddit.
https://en.wikipedia.org/wiki/Full-text_search
My server is based on Dovecot, so first we need to find out what does it support and how can we make it work.
https://doc.dovecot.org/configuration_manual/fts/
Options:
https://en.wikipedia.org/wiki/Xapian
The official installation notes are pretty self explanatory and can be found here
$ apt-get build-dep dovecot-core
$ apt-get install dovecot-dev libxapian30
$ git clone https://github.com/grosjo/fts-xapian
$ cd fts-xapian
$ autoreconf -vi
$ ./configure --with-dovecot=/usr/lib/dovecot
$ make
$ sudo make install
The good people of Debian have packaged it all up, so this is all you need:
apt-get install dovecot-fts-xapian
Add this to the plugin
section of your /etc/dovecot/dovecot.conf
file:
###
### fts-xapian - full text search (source in /opt/fts-xapian)
### https://github.com/grosjo/fts-xapian
###
plugin = fts fts_xapian
fts = xapian
fts_xapian = partial=2 full=20 attachments=0 verbose=0
fts_autoindex = yes
fts_enforced = yes
fts_autoindex_exclude = \Trash
Restart Dovecot:
systemctl restart dovecot
Re-index all the mailboxes:
$ doveadm index -A -q \*
You should see the speed increase in seaches immediatly.
If you check the logs, you will see that the indexing is going on as you search.
/var/log/mail/dovecot.log
Aug 18 14:29:30 sablun dovecot: indexer-worker(xo@sablun.org)<2395994><dsnRCSaazv5ejFqk:U6AOAKrJe18SmyQAv0xPeQ>: Indexed 0 messages in Archive
Aug 18 14:29:30 sablun dovecot: indexer-worker(xo@sablun.org)<2395994><sZzUCSaay/5ejFqk:GBxIAarJe18SmyQAv0xPeQ>: Indexed 0 messages in INBOX