You are here

public function SarniaSolrService::getRemoteFields in Sarnia 7

Get metadata about fields in the Solr/Lucene index.

Parameters

boolean $reset: Reload the cached data?

2 calls to SarniaSolrService::getRemoteFields()
SarniaSolrService::schemaApplyRules in ./service.inc
SarniaSolrService::_getFilteredFields in ./service.inc

File

./service.inc, line 182

Class

SarniaSolrService
Search service class using Solr server.

Code

public function getRemoteFields($reset = FALSE) {
  $cid = 'search_api_solr:fields:' . $this->server->machine_name;

  // If the data hasn't been retrieved before and we aren't refreshing it, try
  // to get data from the cache.
  if (!isset($this->fields) && !$reset) {
    $cache = cache_get($cid);
    if (isset($cache->data)) {
      $this->fields = $cache->data;
    }
  }

  // If there was no data in the cache, or if we're refreshing the data,
  // connect to the Solr server, retrieve schema information, and cache it.
  if (!isset($this->fields) || $reset) {
    $this
      ->connect();
    $this->fields = array();
    try {
      foreach ($this->solr
        ->getFields() as $name => $info) {
        $this->fields[$name] = new SarniaSearchApiSolrField($info, $name);
      }
      cache_set($cid, $this->fields);
    } catch (Exception $e) {
      watchdog('sarnia', 'Could not connect to server %server, %message', array(
        '%server' => $this->server->machine_name,
        '%message' => $e
          ->getMessage(),
      ), WATCHDOG_ERROR);
    }
  }
  return $this->fields;
}