Solr search

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, The QueuedJobs and Fulltextsearch modules need to be installed. The fulltextsearch module must be at least version 3.11.0 in order to support the “post” Solr mode and to include the autocommit fix below, or if using Silverstripe CMS 3, you will need to use version 2.x-dev.

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 4 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.

Was this answer helpful? Yes No

Sorry we couldn't be helpful. Help us improve this article with your feedback.