You are here

public function AcquiaSearchV3ApiClient::getKeys in Acquia Search 2.x

Fetch the search v3 index keys for given core_id and network_id.

Parameters

string $core_id: Core id.

string $network_id: Acquia identifier.

Return value

array|bool|false Search v3 index keys.

File

src/AcquiaSearchV3ApiClient.php, line 133

Class

AcquiaSearchV3ApiClient
Search v3 API Client. (Deprecated, use Acquia Search Solr Module instead)

Namespace

Drupal\acquia_search

Code

public function getKeys($core_id, $network_id) {
  if ($cache = $this->cache
    ->get('acquia_search.v3keys')) {
    if (!empty($cache->data) && $cache->expire > time()) {
      return $cache->data;
    }
  }
  $keys = $this
    ->searchRequest('/index/key?index_name=' . $core_id . '&network_id=' . $network_id);
  if ($keys) {

    // Cache will be set in both cases, 1. when search v3 cores are found and
    // 2. when there are no search v3 cores but api is reachable.
    $this->cache
      ->set('acquia_search.v3keys', $keys, time() + 24 * 60 * 60);
    return $keys;
  }
  else {

    // When api is not reachable, cache it for 1 minute.
    $this->cache
      ->set('acquia_search.v3keys', $keys, time() + 60);
  }
  return FALSE;
}