Setting up Solr on Silverstripe Cloud
Note: Using Solr on Silverstripe Cloud requires an additional server per environment to host the configuration and resources for Solr. If you require one, please talk to your account manager or contact the Service Desk. This document is only relevant to Solr environments created after April 1st 2019.
Some Silverstripe Cloud environments make use of the Solr search engine, if your stack does there are some prerequisites:
Firstly, A solr integration module such as firesphere/solr-search
or silverstripe/fulltextsearch
needs to be installed. This documentation assumes you are using silverstripe/fulltextsearch
.
The same Solr server can be used across the base stack and its virtual stacks but please ensure the index names are different per stack to avoid using the index from stack A on stack B etc. To re-use the Solr server between base and virtual environments make sure to copy the Solr environment variables from the base stack to the virtual stacks.
The following is the minimum Solr configuration required in your _config.php
file for a Silverstripe CMS site:
use SilverStripe\Core\Environment; use SilverStripe\FullTextSearch\Solr\Solr; Solr::configure_server([ 'host' => Environment::getEnv('SOLR_SERVER'), 'port' => Environment::getEnv('SOLR_PORT'), 'path' => Environment::getEnv('SOLR_PATH'), 'version' => Environment::getEnv('SOLR_VERSION'), 'extraspath' => BASE_PATH . '/app/data/solr/extras', 'indexstore' => [ 'mode' => Environment::getEnv('SOLR_MODE'), 'path' => Environment::getEnv('SOLR_INDEXSTORE_PATH'), ], ]);
The SOLR_*
environment variables will be automatically set by the Silverstripe Cloud team after your Solr server has been created. A full deployment will be required in order for them to be applied to each environment.
A cron is also required to run the queued fulltext search jobs, this needs to be added to .platform.yml
:
crons: queuedjobs_task: time: '* * * * *' sake_once: "dev/tasks/ProcessJobQueueTask" vhost: "mysite" ## For a virtual stack, replacing “vstack” with your virtual stack’s code: crons: <vstack>_queuedjobs_task: time: '* * * * *' sake_once: "dev/tasks/ProcessJobQueueTask" vhost: "vstack"
Finally, if using a version prior to 3.11.0 for FulltextSearch, you will need to update your configuration in order for the Solr results to automatically commit - this is because the default fulltextsearch config relies on periodic commits of the Solr index, whereas on Silverstripe Cloud, you will want it to update every time a change is pushed. To do this, copy the default config from the fulltextsearch module into app/data/solr/extras
(or wherever you have configured your extraspath above) and then update the value for autoCommit - openSearcher from false to true:
<autoCommit> <maxTime>${solr.autoCommit.maxTime:15000}</maxTime> <openSearcher>false</openSearcher> </autoCommit>
Once you have this configuration in place you can begin creating your indexes following the documentation. After a successful deployment, you can run Solr_Configure
and Solr_Reindex
to establish a baseline of documents. If you are unable to run a Solr_Configure
, contact the service desk to reload the cores.