You are here

protected function SearchApiSolrConnection::setStats in Search API Solr 7

Stores information about the Solr core in $this->stats.

1 call to SearchApiSolrConnection::setStats()
SearchApiSolrConnection::getStats in includes/solr_connection.inc
Gets information about the Solr core.

File

includes/solr_connection.inc, line 409

Class

SearchApiSolrConnection
Represents a Solr server resource.

Code

protected function setStats() {
  $data = $this
    ->getLuke();
  $solr_version = $this
    ->getSolrVersion();

  // Only try to get stats if we have connected to the index.
  if (empty($this->stats) && isset($data->index->numDocs)) {
    $cid = $this
      ->getCacheId(__FUNCTION__);
    if ($cid) {
      $cache = cache_get($cid, 'cache_search_api_solr');
      if (isset($cache->data)) {
        $this->stats = simplexml_load_string($cache->data);
      }
    }

    // Second pass to populate the cache if necessary.
    if (empty($this->stats)) {
      if ($solr_version >= 4) {
        $url = $this
          ->constructUrl(self::STATS_SERVLET_4);
      }
      else {
        $url = $this
          ->constructUrl(self::STATS_SERVLET);
      }
      $response = $this
        ->sendRawGet($url);
      $this->stats = simplexml_load_string($response->data);
      if ($cid) {
        cache_set($cid, $response->data, 'cache_search_api_solr');
      }
    }
  }
}