You are here

public function StandardSolrCloudConnector::alterConfigFiles in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/SolrConnector/StandardSolrCloudConnector.php \Drupal\search_api_solr\Plugin\SolrConnector\StandardSolrCloudConnector::alterConfigFiles()

Alter the newly assembled Solr configuration files.

Parameters

string[] $files: Array of config files keyed by file names.

string $lucene_match_version: Lucene (Solr) minor version string.

string $server_id: Optional Search API server id. Will be set in most cases but might be empty when the config generation is triggered via UI or drush.

Overrides StandardSolrConnector::alterConfigFiles

File

src/Plugin/SolrConnector/StandardSolrCloudConnector.php, line 427

Class

StandardSolrCloudConnector
Standard Solr Cloud connector.

Namespace

Drupal\search_api_solr\Plugin\SolrConnector

Code

public function alterConfigFiles(array &$files, string $lucene_match_version, string $server_id = '') {
  SolrConnectorPluginBase::alterConfigFiles($files, $lucene_match_version, $server_id);

  // Leverage the implicit Solr request handlers with default settings for
  // Solr Cloud.
  // @see https://lucene.apache.org/solr/guide/8_0/implicit-requesthandlers.html
  if (version_compare($this
    ->getSolrMajorVersion(), '7', '>=')) {
    $files['solrconfig_extra.xml'] = preg_replace("@<requestHandler\\s+name=\"/replication\".*?</requestHandler>@ms", '', $files['solrconfig_extra.xml']);
    $files['solrconfig_extra.xml'] = preg_replace("@<requestHandler\\s+name=\"/get\".*?</requestHandler>@ms", '', $files['solrconfig_extra.xml']);
  }
  else {
    $files['solrconfig.xml'] = preg_replace("@<requestHandler\\s+name=\"/replication\".*?</requestHandler>@ms", '', $files['solrconfig.xml']);
    $files['solrconfig.xml'] = preg_replace("@<requestHandler\\s+name=\"/get\".*?</requestHandler>@ms", '', $files['solrconfig.xml']);
  }

  // Set the StatsCache.
  // @see https://lucene.apache.org/solr/guide/8_0/distributed-requests.html#configuring-statscache-distributed-idf
  if (!empty($this->configuration['stats_cache'])) {
    $files['solrconfig_extra.xml'] .= '<statsCache class="' . $this->configuration['stats_cache'] . '" />' . "\n";
  }
  if (!empty($this->configuration['solr_install_dir'])) {
    $files['solrconfig.xml'] = preg_replace("/{solr\\.install\\.dir:[^}]*}/", '{solr.install.dir:' . $this->configuration['solr_install_dir'] . '}', $files['solrconfig.xml']);
  }
}