You are here

public function SearchApiSolrBackend::getDocumentCounts in Search API Solr 8.3

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

Get document counts for this server, in total and per site / index.

Return value

array An associative array of document counts.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrBackendInterface::getDocumentCounts

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function getDocumentCounts() {
  $document_counts = [
    '#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_counts = $this
          ->doDocumentCounts($collection_endpoint);
        $collection_document_counts['#total'] += $document_counts['#total'];
        $document_counts = ArrayUtils::merge($document_counts, $collection_document_counts, TRUE);
      }
    }
  }
  else {
    $connector = $this
      ->getSolrConnector();
    $connector_endpoint = $connector
      ->getEndpoint();
    return $this
      ->doDocumentCounts($connector_endpoint);
  }
  return $document_counts;
}