You are here

public function SolrConnectorPluginBase::getStatsSummary in Search API Solr 8.2

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

Gets summary information about the Solr Core.

Return value

array An array of stats about the solr core.

Throws

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrConnectorInterface::getStatsSummary

1 call to SolrConnectorPluginBase::getStatsSummary()
StandardSolrCloudConnector::getStatsSummary in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Gets summary information about the Solr Core.
1 method overrides SolrConnectorPluginBase::getStatsSummary()
StandardSolrCloudConnector::getStatsSummary in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Gets summary information about the Solr Core.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 536

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function getStatsSummary() {
  $this
    ->connect();
  $summary = [
    '@pending_docs' => '',
    '@autocommit_time_seconds' => '',
    '@autocommit_time' => '',
    '@deletes_by_id' => '',
    '@deletes_by_query' => '',
    '@deletes_total' => '',
    '@schema_version' => '',
    '@core_name' => '',
    '@index_size' => '',
  ];
  $query = $this->solr
    ->createPing();
  $query
    ->setResponseWriter(Query::WT_PHPS);
  $query
    ->setHandler('admin/mbeans?stats=true');
  $stats = $this
    ->execute($query)
    ->getData();
  if (!empty($stats)) {
    $solr_version = $this
      ->getSolrVersion(TRUE);
    $max_time = -1;
    if (version_compare($solr_version, '7.0', '>=')) {
      $update_handler_stats = $stats['solr-mbeans']['UPDATE']['updateHandler']['stats'];
      $summary['@pending_docs'] = (int) $update_handler_stats['UPDATE.updateHandler.docsPending'];
      if (isset($update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'])) {
        $max_time = (int) $update_handler_stats['UPDATE.updateHandler.softAutoCommitMaxTime'];
      }
      $summary['@deletes_by_id'] = (int) $update_handler_stats['UPDATE.updateHandler.deletesById'];
      $summary['@deletes_by_query'] = (int) $update_handler_stats['UPDATE.updateHandler.deletesByQuery'];
      $summary['@core_name'] = $stats['solr-mbeans']['CORE']['core']['stats']['CORE.coreName'];
      $summary['@index_size'] = $stats['solr-mbeans']['CORE']['core']['stats']['INDEX.size'];
    }
    else {
      $update_handler_stats = $stats['solr-mbeans']['UPDATEHANDLER']['updateHandler']['stats'];
      $summary['@pending_docs'] = (int) $update_handler_stats['docsPending'];
      $max_time = (int) $update_handler_stats['autocommit maxTime'];
      $summary['@deletes_by_id'] = (int) $update_handler_stats['deletesById'];
      $summary['@deletes_by_query'] = (int) $update_handler_stats['deletesByQuery'];
      $summary['@core_name'] = $stats['solr-mbeans']['CORE']['core']['stats']['coreName'];
      if (version_compare($solr_version, '6.4', '>=')) {

        // @see https://issues.apache.org/jira/browse/SOLR-3990
        $summary['@index_size'] = $stats['solr-mbeans']['CORE']['core']['stats']['size'];
      }
      else {
        $summary['@index_size'] = $stats['solr-mbeans']['QUERYHANDLER']['/replication']['stats']['indexSize'];
      }
    }
    $summary['@autocommit_time_seconds'] = $max_time / 1000;
    $summary['@autocommit_time'] = \Drupal::service('date.formatter')
      ->formatInterval($max_time / 1000);
    $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query'];
    $summary['@schema_version'] = $this
      ->getSchemaVersionString(TRUE);
  }
  return $summary;
}