How-to: FTS (full text search) in dovecot using solr

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,340
Location
LT, EU
Install java 8 or greater, check with:
Code:
java -version

Install solr:
Code:
wget -O solr-7.7.0.tgz http://apache.mirror.vu.lt/apache/lucene/solr/7.7.0/solr-7.7.0.tgz
tar xzf solr-7.7.0.tgz solr-7.7.0/bin/install_solr_service.sh --strip-components=2
bash install_solr_service.sh solr-7.7.0.tgz
su -m solr -c "/opt/solr/bin/solr create_core -c dovecot"
curl http://localhost:8983/solr/dovecot/config -d '{"set-user-property": {"update.autoCreateFields":"false"}}'
rm -f /var/solr/data/dovecot/conf/managed-schema

Download /var/solr/data/dovecot/conf/solrconfig.xml:
Code:
wget -O /var/solr/data/dovecot/conf/solrconfig.xml https://raw.githubusercontent.com/dovecot/core/master/doc/solr-config-7.7.0.xml

Download /var/solr/data/dovecot/conf/schema.xml:
Code:
wget -O /var/solr/data/dovecot/conf/schema.xml https://raw.githubusercontent.com/dovecot/core/master/doc/solr-schema-7.7.0.xml

Re-start solr, enable it in chkconfig:
Code:
service solr restart
chkconfig solr on

Configure dovecot for solr:
Code:
cd /usr/local/directadmin/custombuild
mkdir -p custom/dovecot/
cp -p configure/dovecot/configure.dovecot custom/dovecot/

Edit custom/dovecot/configure.dovecot and add:
Code:
--with-solr

Run:
Code:
./build dovecot

Enable plugin in dovecot:
Code:
mkdir -p custom/dovecot/conf/
echo 'mail_plugins = $mail_plugins quota zlib fts fts_solr' > custom/dovecot/conf/mail_plugins.conf

Create /etc/dovecot/conf.d/90-solr.conf:
Code:
plugin {
  fts = solr
  fts_solr = url=http://localhost:8983/solr/dovecot/
}

Rewrite dovecot confs:
Code:
./build dovecot_conf

Optional: ​Don't track user solr processes in lfd:
Code:
echo 'user:solr' >> /etc/csf/csf.pignore
service lfd restart

Logs are stored /var/solr/logs/solr.log, /var/log/maillog shouldn't show errors regarding fts_solr too.
 
Last edited:

kevinwalter

Verified User
Joined
Jun 1, 2011
Messages
48
Change it to this and it's working again. Why not activate this by default? Searching is now much faster. :)

Code:
wget -O solr-7.3.1.tgz [url]http://apache.mirror.vu.lt/apache/lucene/solr/7.3.1/solr-7.3.1.tgz[/url]
tar xzf solr-7.3.1.tgz solr-7.3.1/bin/install_solr_service.sh --strip-components=2
bash install_solr_service.sh solr-7.3.1.tgz
su -m solr -c "/opt/solr/bin/solr create_core -c dovecot"
curl [url]http://localhost:8983/solr/dovecot/config[/url] -d '{"set-user-property": {"update.autoCreateFields":"false"}}'
rm -f /var/solr/data/dovecot/conf/managed-schema
 

SeLLeRoNe

Super Moderator
Joined
Oct 9, 2004
Messages
6,789
Location
A Coruña, Spain
It might be worth add this in the installation:

Code:
for USER in `cat /etc/virtual/domainowners  | cut -d: -f2 | cut -d\  -f2`
        do
        doveadm fts rescan -u $USER
done
To create the indexes for all existing users.

Also I would suggest (if possible) in CB to modify the default dovecot.conf to instead of single loading conf/mail_plugins.conf) to run conf.plugins/* where all the plugins (single file per plugin as per imap quota, solr, sieve, etc) will be stored (and managed by CB in custom/conf.plugins).

Would that be possible?

Thanks for the very useful guide :)

Best regards
 
Top