You are here

public function SearchApiSolrBackend::getMaxDocumentVersions in Search API Solr 4.x

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::getMaxDocumentVersions()

Get the max document versions, in total and per site / index / datasource.

_version_ numbers are important for replication and checkpoints.

Return value

array An associative array of max document versions.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrBackendInterface::getMaxDocumentVersions

1 call to SearchApiSolrBackend::getMaxDocumentVersions()
SearchApiSolrBackend::viewSettings in src/Plugin/search_api/backend/SearchApiSolrBackend.php

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function getMaxDocumentVersions() {
  $document_versions = [
    '#total' => 0,
  ];
  if ($indexes = $this
    ->getServer()
    ->getIndexes()) {
    $connector_endpoints_queried = [];
    foreach ($indexes as $index) {
      $collection_endpoint = $this
        ->getCollectionEndpoint($index);
      $key = $collection_endpoint
        ->getBaseUri();
      if (!in_array($key, $connector_endpoints_queried)) {
        $connector_endpoints_queried[] = $key;
        $collection_document_versions = $this
          ->doGetMaxDocumentVersions($collection_endpoint);
        $collection_document_versions['#total'] += $document_versions['#total'];
        $document_versions = ArrayUtils::merge($document_versions, $collection_document_versions, TRUE);
      }
    }
  }
  else {

    // Try to list versions of orphaned or foreign documents.
    try {
      $connector = $this
        ->getSolrConnector();
      $connector_endpoint = $connector
        ->getEndpoint();
      return $this
        ->doGetMaxDocumentVersions($connector_endpoint);
    } catch (\Exception $e) {

      // Do nothing.
    }
  }
  return $document_versions;
}