You are here

protected function SearchApiAlgoliaBackend::connect in Search API Algolia 8

Same name and namespace in other branches
  1. 3.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::connect()
  2. 2.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::connect()

Creates a connection to the Algolia Search server as configured.

Parameters

\Drupal\search_api\IndexInterface|null $index: Index to connect to.

string $index_suffix: Index suffix, specified when connecting to replica or query suggestion.

string $langcode: Language code to connect to. Specified when doing operations on both languages together.

Throws

\AlgoliaSearch\AlgoliaException

6 calls to SearchApiAlgoliaBackend::connect()
SearchApiAlgoliaBackend::deleteAllIndexItems in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Deletes all the items from the index.
SearchApiAlgoliaBackend::deleteItems in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Deletes the specified items from the index.
SearchApiAlgoliaBackend::getAutocompleteSuggestions in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Implements autocomplete compatible to AutocompleteBackendInterface.
SearchApiAlgoliaBackend::indexItems in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Indexes the specified items.
SearchApiAlgoliaBackend::search in src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php
Executes a search on this server.

... See full list

File

src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php, line 495

Class

SearchApiAlgoliaBackend
Class SearchApiAlgoliaBackend.

Namespace

Drupal\search_api_algolia\Plugin\search_api\backend

Code

protected function connect(?IndexInterface $index = NULL, $index_suffix = '', $langcode = '') {
  if (!$this
    ->getAlgolia()) {
    $this->algoliaClient = new Client($this
      ->getApplicationId(), $this
      ->getApiKey());
  }
  if ($index && $index instanceof IndexInterface) {
    $indexId = $index
      ->getOption('algolia_index_name') ? $index
      ->getOption('algolia_index_name') : $index
      ->get('id');
    if ($this->languageManager
      ->isMultilingual()) {
      $langcode = $langcode ?: $this->languageManager
        ->getCurrentLanguage()
        ->getId();
      $indexId .= '_' . $langcode;
    }
    $indexId .= $index_suffix;
    $this
      ->setAlgoliaIndex($this->algoliaClient
      ->initIndex($indexId));
  }
}