You are here

public function AcquiaSearchV3ApiClient::getSearchV3Indexes in Acquia Connector 8

Helper function to fetch all search v3 indexes for given network_id.

Parameters

string $network_id: Subscription network id.

Return value

array|false Response array or FALSE

File

acquia_search/src/AcquiaSearchV3ApiClient.php, line 91

Class

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

Namespace

Drupal\acquia_search

Code

public function getSearchV3Indexes($network_id) {
  $result = [];
  if ($cache = $this->cache
    ->get('acquia_search.v3indexes')) {
    if (is_array($cache->data) && $cache->expire > time()) {
      return $cache->data;
    }
  }
  $indexes = $this
    ->searchRequest('/index/network_id/get_all?network_id=' . $network_id);
  if (is_array($indexes)) {
    if (!empty($indexes)) {
      foreach ($indexes as $index) {
        $result[] = [
          'balancer' => $index['host'],
          'core_id' => $index['name'],
          'version' => 'v3',
        ];
      }
    }

    // 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.v3indexes', $result, time() + 24 * 60 * 60);
    return $result;
  }
  else {

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