Source of file CwpSolr.php
Size: 4,327 Bytes - Last Modified: 2021-12-24T06:43:21+00:00
/var/www/docs.ssmods.com/process/src/src/Solr/CwpSolr.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 | <?php namespace CWP\Search\Solr; use InvalidArgumentException; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Environment; use SilverStripe\FullTextSearch\Solr\Solr; /** * CwpSolr configures Solr in a CWP-compatible manner. */ class CwpSolr { use Configurable; /** * * @var array */ private static $options; /** * Configure Solr. * * $options - An array consisting of: * * 'extraspath' - (String) Where to find Solr core configuartion files. * Defaults to '<BASE_PATH>/app/conf/extras'. * 'version' - select the Solr configuration to use when in CWP. One of: * * 'cwp-4': preferred version, uses secured 4.x service available on CWP * * 'local-4': this can be use for development using silverstripe-localsolr package, 4.x branch */ public static function configure() { if (!class_exists(Solr::class)) { return; } // get options from configuration $options = static::config()->get('options'); // get version specific options switch ($options['version']) { case 'cwp-4': $solrOptions = self::options_for_cwp($options); break; case 'local-4': $solrOptions = self::options_for_local($options); break; default: throw new InvalidArgumentException(sprintf( 'Solr version "%s" is not supported on CWP. Please use "local-4" on local ' . 'and "cwp-4" on production. For preferred configuration see ' . 'https://www.cwp.govt.nz/developer-docs/.', $options['version'] )); break; } // Allow users to override extras path. // CAUTION: CWP does not permit usage of customised solrconfig.xml. if (isset($options['extraspath']) && file_exists($options['extraspath'])) { $solrOptions['extraspath'] = $options['extraspath']; } elseif (file_exists(BASE_PATH . '/app/conf/extras')) { $solrOptions['extraspath'] = BASE_PATH . '/app/conf/extras'; } Solr::configure_server($solrOptions); } /** * @param array $options * @return array */ public static function options_for_cwp($options) { $version = $options['version']; return [ 'host' => Environment::getEnv('SOLR_SERVER'), 'port' => Environment::getEnv('SOLR_PORT'), 'path' => '/v4/', 'version' => 4, 'indexstore' => [ 'mode' => 'post', 'path' => '/v4', ], ]; } /** * * @param array $options * @return array */ public static function options_for_local($options) { return [ 'host' => Environment::getEnv('SOLR_SERVER') ? Environment::getEnv('SOLR_SERVER') : 'localhost', 'port' => Environment::getEnv('SOLR_PORT') ? Environment::getEnv('SOLR_PORT') : 8983, 'path' => Environment::getEnv('SOLR_PATH') ? Environment::getEnv('SOLR_PATH') : '/solr/', 'version' => 4, 'indexstore' => [ 'mode' => Environment::getEnv('SOLR_MODE') ? Environment::getEnv('SOLR_MODE') : 'file', 'auth' => Environment::getEnv('SOLR_AUTH') ? Environment::getEnv('SOLR_AUTH') : null, // Allow storing the solr index and config data in an arbitrary location, // e.g. outside of the webroot 'path' => Environment::getEnv('SOLR_INDEXSTORE_PATH') ? Environment::getEnv('SOLR_INDEXSTORE_PATH') : BASE_PATH . '/.solr', 'remotepath' => Environment::getEnv('SOLR_REMOTE_PATH') ? Environment::getEnv('SOLR_REMOTE_PATH') : null, 'port' => Environment::getEnv('SOLR_INDEXSTORE_PORT') ? Environment::getEnv('SOLR_INDEXSTORE_PORT') : ( Environment::getEnv('SOLR_PORT') ? Environment::getEnv('SOLR_PORT') : 8983 ) ] ]; } } |