You are here

public function SolrConnectorPluginBase::getSolrVersion in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getSolrVersion()
  2. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getSolrVersion()
  3. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getSolrVersion()

Gets the current Solr version.

Parameters

bool $force_auto_detect: If TRUE, ignore user overwrites.

Return value

string The full Solr version string.

Overrides SolrConnectorInterface::getSolrVersion

4 calls to SolrConnectorPluginBase::getSolrVersion()
SolrConnectorPluginBase::getLuceneMatchVersion in src/SolrConnector/SolrConnectorPluginBase.php
Gets the LuceneMatchVersion string.
SolrConnectorPluginBase::getSolrMajorVersion in src/SolrConnector/SolrConnectorPluginBase.php
Gets the current Solr major version.
SolrConnectorPluginBase::getStatsSummary in src/SolrConnector/SolrConnectorPluginBase.php
Gets summary information about the Solr Core.
StandardSolrCloudConnector::getStatsSummary in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Gets summary information about the Solr Core.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 413

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function getSolrVersion($force_auto_detect = FALSE) {

  // Allow for overrides by the user.
  if (!$force_auto_detect && !empty($this->configuration['solr_version'])) {

    // In most cases the already stored solr_version is just the major version
    // number as integer. In this case we will expand it to the minimum
    // corresponding full version string.
    $min_version = [
      '0',
      '0',
      '0',
    ];
    $version = implode('.', explode('.', $this->configuration['solr_version']) + $min_version);
    switch ($version) {
      case '3.0.0':

        // 3.6.0 is the minimum supported Solr 3 version by the
        // search_api_solr_legacy module.
        $version = '3.6.0';
        break;
      case '4.0.0':

        // 4.5.0 is the minimum supported Solr 4 version by the
        // search_api_solr_legacy module.
        $version = '4.5.0';
        break;
      case '6.0.0':

        // 6.4.0 is the minimum supported Solr version. Earlier Solr 6
        // versions should run in Solr 5 compatibility mode using the
        // search_api_solr_legacy module.
        $version = '6.4.0';
        break;
    }
    return $version;
  }
  $info = [];
  try {
    $info = $this
      ->getCoreInfo();
  } catch (\Exception $e) {
    try {
      $info = $this
        ->getServerInfo();
    } catch (SearchApiSolrException $e) {
    }
  }

  // Get our solr version number.
  if (isset($info['lucene']['solr-spec-version'])) {

    // Some Solr distributions or docker images append additional info to the
    // version number, for example the build date: 3.6.2.2012.12.18.19.52.27.
    if (preg_match('/^(\\d+\\.\\d+\\.\\d+)/', $info['lucene']['solr-spec-version'], $matches)) {
      return $matches[1];
    }
  }
  return '0.0.0';
}