You are here

public function SearchApiSolrService::getExtraInformation in Search API Solr 7

Returns additional, service-specific information about this server.

If a service class implements this method and supports the "search_api_service_extra" option, this method will be used to add extra information to the server's "View" tab.

In the default theme implementation this data will be output in a table with two columns along with other, generic information about the server.

Return value

array An array of additional server information, with each piece of information being an associative array with the following keys:

  • label: The human-readable label for this data.
  • info: The information, as HTML.
  • status: (optional) The status associated with this information. One of "info", "ok", "warning" or "error". Defaults to "info".

Overrides SearchApiAbstractService::getExtraInformation

See also

supportsFeature()

File

includes/service.inc, line 412

Class

SearchApiSolrService
Search service class using Solr server.

Code

public function getExtraInformation() {
  $info = array();
  $info[] = array(
    'label' => t('Solr server URI'),
    'info' => $this
      ->getServerLink(),
  );
  if ($this->options['http_user']) {
    $vars = array(
      '@user' => $this->options['http_user'],
      '@pass' => str_repeat('*', strlen($this->options['http_pass'])),
    );
    $http = t('Username: @user; Password: @pass', $vars);
    $info[] = array(
      'label' => t('Basic HTTP authentication'),
      'info' => $http,
    );
  }
  if ($this->server->enabled) {

    // If the server is enabled, check whether Solr can be reached.
    $ping = $this
      ->ping();
    if ($ping) {
      $msg = t('The Solr server could be reached (latency: @millisecs ms).', array(
        '@millisecs' => $ping * 1000,
      ));
    }
    else {
      $msg = t('The Solr server could not be reached. Further data is therefore unavailable.');
    }
    $info[] = array(
      'label' => t('Connection'),
      'info' => $msg,
      'status' => $ping ? 'ok' : 'error',
    );
    if ($ping) {
      try {

        // If Solr can be reached, provide more information. This isn't done
        // often (only when an admin views the server details), so we clear the
        // cache to get the current data.
        $this
          ->connect();
        $this->solr
          ->clearCache();
        $data = $this->solr
          ->getLuke();
        if (isset($data->index->numDocs)) {

          // Collect the stats
          $stats_summary = $this->solr
            ->getStatsSummary();
          $pending_msg = $stats_summary['@pending_docs'] ? t('(@pending_docs sent but not yet processed)', $stats_summary) : '';
          $index_msg = $stats_summary['@index_size'] ? t('(@index_size on disk)', $stats_summary) : '';
          $indexed_message = t('@num items !pending !index_msg', array(
            '@num' => $data->index->numDocs,
            '!pending' => $pending_msg,
            '!index_msg' => $index_msg,
          ));
          $info[] = array(
            'label' => t('Indexed'),
            'info' => $indexed_message,
          );
          if (!empty($stats_summary['@deletes_total'])) {
            $info[] = array(
              'label' => t('Pending Deletions'),
              'info' => $stats_summary['@deletes_total'],
            );
          }
          $info[] = array(
            'label' => t('Delay'),
            'info' => t('@autocommit_time before updates are processed.', $stats_summary),
          );
          $status = 'ok';
          if (empty($this->options['skip_schema_check'])) {
            if (substr($stats_summary['@schema_version'], 0, 10) == 'search-api') {
              drupal_set_message(t('Your schema.xml version is too old. Please replace all configuration files with the ones packaged with this module and re-index you data.'), 'error');
              $status = 'error';
            }
            elseif (substr($stats_summary['@schema_version'], 0, 9) != 'drupal-4.') {
              $variables['@url'] = url('https://www.drupal.org/node/1999310');
              $message = t('You are using an incompatible schema.xml configuration file. Please follow the instructions in <a href="@url">the handbook</a> for setting up Solr.', $variables);
              drupal_set_message($message, 'error');
              $status = 'error';
            }
          }
          $info[] = array(
            'label' => t('Schema'),
            'info' => $stats_summary['@schema_version'],
            'status' => $status,
          );
          if (!empty($stats_summary['@core_name'])) {
            $info[] = array(
              'label' => t('Solr Core Name'),
              'info' => $stats_summary['@core_name'],
            );
          }
        }
      } catch (SearchApiException $e) {
        $info[] = array(
          'label' => t('Additional information'),
          'info' => t('An error occurred while trying to retrieve additional information from the Solr server: @msg.', array(
            '@msg' => $e
              ->getMessage(),
          )),
          'status' => 'error',
        );
      }
    }
  }
  return $info;
}