You are here

public function SearchApiSolrBackend::viewSettings in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::viewSettings()
  2. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::viewSettings()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::viewSettings()

Returns additional, backend-specific information about this server.

This information will be then added to the server's "View" tab in some way. In the default theme implementation the data is 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 BackendPluginBase::viewSettings

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 492

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function viewSettings() {
  $connector = $this
    ->getSolrConnector();
  $info[] = [
    'label' => $this
      ->t('Solr connector plugin'),
    'info' => $connector
      ->label(),
  ];
  $info[] = [
    'label' => $this
      ->t('Solr server URI'),
    'info' => $connector
      ->getServerLink(),
  ];
  $info[] = [
    'label' => $this
      ->t('Solr core URI'),
    'info' => $connector
      ->getCoreLink(),
  ];

  // Add connector-specific information.
  $info = array_merge($info, $connector
    ->viewSettings());
  if ($this->server
    ->status()) {

    // If the server is enabled, check whether Solr can be reached.
    $ping_server = $connector
      ->pingServer();
    if ($ping_server) {
      $msg = $this
        ->t('The Solr server could be reached.');
    }
    else {
      $msg = $this
        ->t('The Solr server could not be reached or is protected by your service provider.');
    }
    $info[] = [
      'label' => $this
        ->t('Server Connection'),
      'info' => $msg,
      'status' => $ping_server ? 'ok' : 'error',
    ];
    $ping = $connector
      ->pingCore();
    if ($ping) {
      $msg = $this
        ->t('The Solr core could be accessed (latency: @millisecs ms).', [
        '@millisecs' => $ping * 1000,
      ]);
    }
    else {
      $msg = $this
        ->t('The Solr core could not be accessed. Further data is therefore unavailable.');
    }
    $info[] = [
      'label' => $this
        ->t('Core Connection'),
      'info' => $msg,
      'status' => $ping ? 'ok' : 'error',
    ];
    $version = $connector
      ->getSolrVersion();
    $info[] = [
      'label' => $this
        ->t('Configured Solr Version'),
      'info' => $version,
      'status' => version_compare($version, '0.0.0', '>') ? 'ok' : 'error',
    ];
    if ($ping_server || $ping) {
      $info[] = [
        'label' => $this
          ->t('Detected Solr Version'),
        'info' => $connector
          ->getSolrVersion(TRUE),
        'status' => 'ok',
      ];
      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.
        $data = $connector
          ->getLuke();
        if (isset($data['index']['numDocs'])) {

          // Collect the stats.
          $stats_summary = $connector
            ->getStatsSummary();
          $pending_msg = $stats_summary['@pending_docs'] ? $this
            ->t('(@pending_docs sent but not yet processed)', $stats_summary) : '';
          $index_msg = $stats_summary['@index_size'] ? $this
            ->t('(@index_size on disk)', $stats_summary) : '';
          $indexed_message = $this
            ->t('@num items @pending @index_msg', array(
            '@num' => $data['index']['numDocs'],
            '@pending' => $pending_msg,
            '@index_msg' => $index_msg,
          ));
          $info[] = [
            'label' => $this
              ->t('Indexed'),
            'info' => $indexed_message,
          ];
          if (!empty($stats_summary['@deletes_total'])) {
            $info[] = [
              'label' => $this
                ->t('Pending Deletions'),
              'info' => $stats_summary['@deletes_total'],
            ];
          }
          $info[] = [
            'label' => $this
              ->t('Delay'),
            'info' => $this
              ->t('@autocommit_time before updates are processed.', $stats_summary),
          ];
          $status = 'ok';
          if (empty($this->configuration['skip_schema_check'])) {
            if (substr($stats_summary['@schema_version'], 0, 10) == 'search-api') {
              $this
                ->messenger()
                ->addError('Your schema.xml version is too old. Please replace all configuration files with the ones packaged with this module and re-index you data.');
              $status = 'error';
            }
            elseif (!preg_match('/drupal-[' . SEARCH_API_SOLR_MIN_SCHEMA_VERSION . '-9]\\./', $stats_summary['@schema_version'])) {
              $variables['@url'] = Url::fromUri('internal:/' . drupal_get_path('module', 'search_api_solr') . '/INSTALL.txt')
                ->toString();
              $message = $this
                ->t('You are using an incompatible schema.xml configuration file. Please follow the instructions in the <a href="@url">INSTALL.txt</a> file for setting up Solr.', $variables);
              $this
                ->messenger()
                ->addError($message);
              $status = 'error';
            }
          }
          $info[] = [
            'label' => $this
              ->t('Schema'),
            'info' => $stats_summary['@schema_version'],
            'status' => $status,
          ];
          if (!empty($stats_summary['@core_name'])) {
            $info[] = [
              'label' => $this
                ->t('Solr Core Name'),
              'info' => $stats_summary['@core_name'],
            ];
          }
        }
      } catch (SearchApiException $e) {
        $info[] = [
          'label' => $this
            ->t('Additional information'),
          'info' => $this
            ->t('An error occurred while trying to retrieve additional information from the Solr server: %msg', [
            '%msg' => $e
              ->getMessage(),
          ]),
          'status' => 'error',
        ];
      }
    }
  }
  if ($this->moduleHandler
    ->moduleExists('search_api_autocomplete')) {
    $autocomplete_modes = [];
    if ($this->configuration['suggest_suffix']) {
      $autocomplete_modes[] = $this
        ->t('Suggest word endings');
    }
    if ($this->configuration['suggest_corrections']) {
      $autocomplete_modes[] = $this
        ->t('Suggest corrected words');
    }
    if ($this->configuration['suggest_words']) {
      $autocomplete_modes[] = $this
        ->t('Suggest additional words');
    }
    $info[] = [
      'label' => $this
        ->t('Autocomplete suggestions'),
      'info' => !empty($autocomplete_modes) ? implode('; ', $autocomplete_modes) : $this
        ->t('none'),
    ];
  }
  return $info;
}