You are here

class SearchApiAlgoliaBackend 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
  2. 2.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend

Class SearchApiAlgoliaBackend.

Plugin annotation


@SearchApiBackend(
  id = "search_api_algolia",
  label = @Translation("Algolia"),
  description = @Translation("Index items using a Algolia Search.")
)

Hierarchy

Expanded class hierarchy of SearchApiAlgoliaBackend

File

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

Namespace

Drupal\search_api_algolia\Plugin\search_api\backend
View source
class SearchApiAlgoliaBackend extends BackendPluginBase implements PluginFormInterface {
  use PluginFormTrait;

  /**
   * Algolia Index.
   *
   * @var \AlgoliaSearch\Index
   */
  protected $algoliaIndex = NULL;

  /**
   * A connection to the Algolia server.
   *
   * @var \AlgoliaSearch\Client
   */
  protected $algoliaClient;

  /**
   * The logger to use for logging messages.
   *
   * @var \Psr\Log\LoggerInterface|null
   */
  protected $logger;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->languageManager = $language_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $backend = new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('language_manager'));

    /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
    $module_handler = $container
      ->get('module_handler');
    $backend
      ->setModuleHandler($module_handler);

    /** @var \Psr\Log\LoggerInterface $logger */
    $logger = $container
      ->get('logger.channel.search_api_algolia');
    $backend
      ->setLogger($logger);
    return $backend;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'application_id' => '',
      'api_key' => '',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['help'] = [
      '#markup' => '<p>' . $this
        ->t('The application ID and API key an be found and configured at <a href="@link" target="blank">@link</a>.', [
        '@link' => 'https://www.algolia.com/licensing',
      ]) . '</p>',
    ];
    $form['application_id'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Application ID'),
      '#description' => $this
        ->t('The application ID from your Algolia subscription.'),
      '#default_value' => $this
        ->getApplicationId(),
      '#required' => TRUE,
      '#size' => 60,
      '#maxlength' => 128,
    ];
    $form['api_key'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('API Key'),
      '#description' => $this
        ->t('The API key from your Algolia subscription.'),
      '#default_value' => $this
        ->getApiKey(),
      '#required' => TRUE,
      '#size' => 60,
      '#maxlength' => 128,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function viewSettings() {
    try {
      $this
        ->connect();
    } catch (\Exception $e) {
      $this
        ->getLogger()
        ->warning('Could not connect to Algolia backend.');
    }
    $info = [];

    // Application ID.
    $info[] = [
      'label' => $this
        ->t('Application ID'),
      'info' => $this
        ->getApplicationId(),
    ];

    // API Key.
    $info[] = [
      'label' => $this
        ->t('API Key'),
      'info' => $this
        ->getApiKey(),
    ];

    // Available indexes.
    $indexes = $this
      ->getAlgolia()
      ->listIndexes();
    $indexes_list = [];
    if (isset($indexes['items'])) {
      foreach ($indexes['items'] as $index) {
        $indexes_list[] = $index['name'];
      }
    }
    $info[] = [
      'label' => $this
        ->t('Available Algolia indexes'),
      'info' => implode(', ', $indexes_list),
    ];
    return $info;
  }

  /**
   * {@inheritdoc}
   */
  public function removeIndex($index) {

    // Only delete the index's data if the index isn't read-only.
    if (!is_object($index) || empty($index
      ->get('read_only'))) {
      $this
        ->deleteAllIndexItems($index);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function indexItems(IndexInterface $index, array $items) {
    $objects = [];

    /** @var \Drupal\search_api\Item\ItemInterface[] $items */
    foreach ($items as $id => $item) {
      $objects[$id] = $this
        ->prepareItem($index, $item);
    }

    // Let other modules alter objects before sending them to Algolia.
    $this
      ->alterAlgoliaObjects($objects, $index, $items);
    if (count($objects) > 0) {
      $itemsToIndex = [];
      if ($this->languageManager
        ->isMultilingual()) {
        foreach ($objects as $item) {
          $itemsToIndex[$item['search_api_language']][] = $item;
        }
      }
      else {
        $itemsToIndex[''] = $objects;
      }
      foreach ($itemsToIndex as $language => $items) {
        try {
          $this
            ->connect($index, '', $language);
          $this
            ->getAlgoliaIndex()
            ->saveObjects($items);
        } catch (AlgoliaException $e) {
          $this
            ->getLogger()
            ->warning(Html::escape($e
            ->getMessage()));
        }
      }
    }
    return array_keys($objects);
  }

  /**
   * Indexes a single item on the specified index.
   *
   * @param \Drupal\search_api\IndexInterface $index
   *   The index for which the item is being indexed.
   * @param \Drupal\search_api\Item\ItemInterface $item
   *   The item to index.
   */
  protected function indexItem(IndexInterface $index, ItemInterface $item) {
    $this
      ->indexItems([
      $item
        ->getId() => $item,
    ]);
  }

  /**
   * Prepares a single item for indexing.
   *
   * Used as a helper method in indexItem()/indexItems().
   *
   * @param \Drupal\search_api\IndexInterface $index
   *   Index.
   * @param \Drupal\search_api\Item\ItemInterface $item
   *   The item to index.
   */
  protected function prepareItem(IndexInterface $index, ItemInterface $item) {
    $item_id = $item
      ->getId();
    $item_to_index = [
      'objectID' => $item_id,
    ];

    /** @var \Drupal\search_api\Item\FieldInterface $field */
    $item_fields = $item
      ->getFields();
    $item_fields += $this
      ->getSpecialFields($index, $item);
    foreach ($item_fields as $field) {
      $type = $field
        ->getType();
      $values = NULL;
      $field_values = $field
        ->getValues();
      if (empty($field_values)) {
        continue;
      }
      foreach ($field_values as $field_value) {
        if (!$field_value) {
          continue;
        }
        switch ($type) {
          case 'text':
          case 'string':
          case 'uri':
            $field_value .= '';
            if (mb_strlen($field_value) > 10000) {
              $field_value = mb_substr(trim($field_value), 0, 10000);
            }
            $values[] = $field_value;
            break;
          case 'integer':
          case 'duration':
          case 'decimal':
            $values[] = 0 + $field_value;
            break;
          case 'boolean':
            $values[] = $field_value ? TRUE : FALSE;
            break;
          case 'date':
            if (is_numeric($field_value) || !$field_value) {
              $values[] = 0 + $field_value;
              break;
            }
            $values[] = strtotime($field_value);
            break;
          default:
            $values[] = $field_value;
        }
      }
      if (is_array($values) && count($values) <= 1) {
        $values = reset($values);
      }
      $item_to_index[$field
        ->getFieldIdentifier()] = $values;
    }
    return $item_to_index;
  }

  /**
   * Applies custom modifications to indexed Algolia objects.
   *
   * This method allows subclasses to easily apply custom changes before the
   * objects are sent to Algolia.
   *
   * @param array $objects
   *   An array of objects ready to be indexed, generated from $items array.
   * @param \Drupal\search_api\IndexInterface $index
   *   The search index for which items are being indexed.
   * @param array $items
   *   An array of items being indexed.
   *
   * @see hook_search_api_algolia_objects_alter()
   */
  protected function alterAlgoliaObjects(array &$objects, IndexInterface $index, array $items) {
    $this
      ->getModuleHandler()
      ->alter('search_api_algolia_objects', $objects, $index, $items);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteItems(IndexInterface $index, array $ids) {

    // Deleting all items included in the $ids array.
    if ($this->languageManager
      ->isMultilingual()) {
      foreach ($this->languageManager
        ->getLanguages() as $language) {
        try {

          // Connect to the Algolia index for specific language.
          $this
            ->connect($index, '', $language
            ->getId());
        } catch (\Exception $e) {
          $this
            ->getLogger()
            ->error('Failed to connect to Algolia index while deleting indexed items, Error: @message', [
            '@message' => $e
              ->getMessage(),
          ]);
          return;
        }
        $this
          ->getAlgoliaIndex()
          ->deleteObjects($ids);
      }
    }
    else {

      // Connect to the Algolia index.
      try {
        $this
          ->connect($index);
      } catch (\Exception $e) {
        $this
          ->getLogger()
          ->error('Failed to connect to Algolia index while deleting indexed items, Error: @message', [
          '@message' => $e
            ->getMessage(),
        ]);
        return;
      }
      $this
        ->getAlgoliaIndex()
        ->deleteObjects($ids);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function deleteAllIndexItems(IndexInterface $index = NULL, $datasource_id = NULL) {
    if ($index) {
      if ($this->languageManager
        ->isMultilingual()) {
        foreach ($this->languageManager
          ->getLanguages() as $language) {

          // Connect to the Algolia service.
          $this
            ->connect($index, '', $language
            ->getId());

          // Clearing the full index.
          $this
            ->getAlgoliaIndex()
            ->clearIndex();
        }
      }
      else {

        // Connect to the Algolia service.
        $this
          ->connect($index);

        // Clearing the full index.
        $this
          ->getAlgoliaIndex()
          ->clearIndex();
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function search(QueryInterface $query) {
    $results = $query
      ->getResults();
    $options = $query
      ->getOptions();
    $sorts = $query
      ->getSorts() ?? [];
    $search_api_index = $query
      ->getIndex();
    $suffix = '';

    // Allow other modules to remove sorts handled in index rankings.
    $this
      ->getModuleHandler()
      ->alter('search_api_algolia_sorts', $sorts, $search_api_index);

    // Get the first sort to build replica name.
    // Replicas must be created with format PRIMARYINDEXNAME_FIELD_DIRECTION.
    // For instance index_stock_desc.
    foreach ($sorts as $field => $direction) {
      $suffix = '_' . strtolower($field . '_' . $direction);
      break;
    }
    try {
      $this
        ->connect($search_api_index, $suffix);
      $index = $this
        ->getAlgoliaIndex();
    } catch (\Exception $e) {
      $this
        ->getLogger()
        ->error('Failed to connect to Algolia index while searching with suffix: @suffix, Error: @message', [
        '@message' => $e
          ->getMessage(),
        '@suffix' => $suffix,
      ]);
      return $results;
    }
    $facets = isset($options['search_api_facets']) ? array_column($options['search_api_facets'], 'field') : [];
    $algolia_options = [
      'attributesToRetrieve' => [
        'search_api_id',
      ],
      'facets' => $facets,
      'analytics' => TRUE,
    ];
    if (!empty($options['limit'])) {
      $algolia_options['length'] = $options['limit'];
      $algolia_options['offset'] = $options['offset'];
    }
    $this
      ->extractConditions($query
      ->getConditionGroup(), $algolia_options, $facets);

    // Algolia expects indexed arrays, remove the keys.
    if (isset($algolia_options['facetFilters'])) {
      $algolia_options['facetFilters'] = array_values($algolia_options['facetFilters']);
    }
    if (isset($algolia_options['disjunctiveFacets'])) {
      $algolia_options['disjunctiveFacets'] = array_values($algolia_options['disjunctiveFacets']);
    }

    // Filters and disjunctiveFacets are not supported together by Algolia.
    if (!empty($algolia_options['filters']) && !empty($algolia_options['disjunctiveFacets'])) {
      unset($algolia_options['disjunctiveFacets']);
    }
    $keys = $query
      ->getOriginalKeys();
    $search = empty($keys) ? '*' : $keys;
    $data = $index
      ->search($search, $algolia_options);
    $results
      ->setResultCount($data['nbHits']);
    foreach ($data['hits'] ?? [] as $row) {
      $item = $this
        ->getFieldsHelper()
        ->createItem($query
        ->getIndex(), $row['search_api_id']);
      $results
        ->addResultItem($item);
    }
    if (isset($data['facets'])) {
      $results
        ->setExtraData('search_api_facets', $this
        ->extractFacetsData($facets, $data['facets']));
    }
    return $results;
  }

  /**
   * Creates a connection to the Algolia Search server as configured.
   *
   * @param \Drupal\search_api\IndexInterface|null $index
   *   Index to connect to.
   * @param string $index_suffix
   *   Index suffix, specified when connecting to replica or query suggestion.
   * @param string $langcode
   *   Language code to connect to.
   *   Specified when doing operations on both languages together.
   *
   * @throws \AlgoliaSearch\AlgoliaException
   */
  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));
    }
  }

  /**
   * Retrieves the list of available Algolia indexes.
   *
   * @return array
   *   List of indexes on Algolia.
   */
  public function listIndexes() {
    $algoliaClient = new Client($this
      ->getApplicationId(), $this
      ->getApiKey());
    $indexes = $algoliaClient
      ->listIndexes();
    $indexes_list = [];
    if (isset($indexes['items'])) {
      foreach ($indexes['items'] as $index) {
        $indexes_list[$index['name']] = $index['name'];
      }
    }
    return $indexes_list;
  }

  /**
   * Retrieves the logger to use.
   *
   * @return \Psr\Log\LoggerInterface
   *   The logger to use.
   */
  public function getLogger() {
    return $this->logger;
  }

  /**
   * Sets the logger to use.
   *
   * @param \Psr\Log\LoggerInterface $logger
   *   The logger to use.
   *
   * @return $this
   */
  public function setLogger(LoggerInterface $logger) {
    $this->logger = $logger;
    return $this;
  }

  /**
   * Returns the module handler to use for this plugin.
   *
   * @return \Drupal\Core\Extension\ModuleHandlerInterface
   *   The module handler.
   */
  public function getModuleHandler() {
    return $this->moduleHandler ?: \Drupal::moduleHandler();
  }

  /**
   * Sets the module handler to use for this plugin.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to use for this plugin.
   *
   * @return $this
   */
  public function setModuleHandler(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
    return $this;
  }

  /**
   * Returns the AlgoliaSearch client.
   *
   * @return \AlgoliaSearch\Client
   *   The algolia instance object.
   */
  public function getAlgolia() {
    return $this->algoliaClient;
  }

  /**
   * Get the Algolia index.
   *
   * @returns \AlgoliaSearch\Index
   *   Index.
   */
  protected function getAlgoliaIndex() {
    return $this->algoliaIndex;
  }

  /**
   * Set the Algolia index.
   */
  protected function setAlgoliaIndex($index) {
    $this->algoliaIndex = $index;
  }

  /**
   * Get the ApplicationID (provided by Algolia).
   */
  protected function getApplicationId() {
    return $this->configuration['application_id'];
  }

  /**
   * Get the API key (provided by Algolia).
   */
  protected function getApiKey() {
    return $this->configuration['api_key'];
  }

  /**
   * {@inheritdoc}
   */
  public function getSupportedFeatures() {
    return [
      'search_api_autocomplete',
      'search_api_facets',
      'search_api_facets_operator_or',
    ];
  }

  /**
   * Extract facets data from response.
   *
   * @param array $facets
   *   Facets to extract.
   * @param array $data
   *   Facets data from response.
   *
   * @return array
   *   Facets data in format required by Drupal.
   */
  private function extractFacetsData(array $facets, array $data) {
    $facets_data = [];
    foreach ($data as $field => $facet_data) {
      if (!in_array($field, $facets)) {
        continue;
      }
      foreach ($facet_data as $value => $count) {
        $facets_data[$field][] = [
          'count' => $count,
          'filter' => '"' . $value . '"',
        ];
      }
    }
    return $facets_data;
  }

  /**
   * Extract conditions.
   *
   * @param \Drupal\search_api\Query\ConditionGroupInterface $condition_group
   *   Condition group.
   * @param array $options
   *   Algolia options to updatesearch_api_algolia.module.
   * @param array $facets
   *   Facets.
   */
  private function extractConditions(ConditionGroupInterface $condition_group, array &$options, array $facets) {
    foreach ($condition_group
      ->getConditions() as $condition) {
      if ($condition instanceof ConditionGroupInterface) {
        $this
          ->extractConditions($condition, $options, $facets);
        continue;
      }
      $field = $condition
        ->getField();

      /** @var \Drupal\search_api\Query\Condition $condition */

      // We support limited operators for now.
      if ($condition
        ->getOperator() == '=') {
        $query = $field . ':' . $condition
          ->getValue();
        if (in_array($field, $facets)) {
          $options['facetFilters'][$field][] = $query;
          $options['disjunctiveFacets'][$field] = $field;
        }
        else {
          $options['filters'] = isset($options['filters']) ? ' AND ' . $query : $query;
        }
      }
      elseif (in_array($condition
        ->getOperator(), [
        '<',
        '>',
        '<=',
        '>=',
      ])) {
        $options['numericFilters'][] = $field . ' ' . $condition
          ->getOperator() . ' ' . $condition
          ->getValue();
      }
    }
  }

  /**
   * Implements autocomplete compatible to AutocompleteBackendInterface.
   *
   * @param \Drupal\search_api\Query\QueryInterface $query
   *   A query representing the completed user input so far.
   * @param \Drupal\search_api_autocomplete\SearchInterface $search
   *   An object containing details about the search the user is on, and
   *   settings for the autocompletion. See the class documentation for details.
   *   Especially $search->options should be checked for settings, like whether
   *   to try and estimate result counts for returned suggestions.
   * @param string $incomplete_key
   *   The start of another fulltext keyword for the search, which should be
   *   completed. Might be empty, in which case all user input up to now was
   *   considered completed. Then, additional keywords for the search could be
   *   suggested.
   * @param string $user_input
   *   The complete user input for the fulltext search keywords so far.
   *
   * @return \Drupal\search_api_autocomplete\Suggestion\SuggestionInterface[]
   *   An array of suggestions.
   *
   * @see \Drupal\search_api_autocomplete\AutocompleteBackendInterface
   */
  public function getAutocompleteSuggestions(QueryInterface $query, SearchInterface $search, $incomplete_key, $user_input) {
    $suggestions = [];
    if (class_exists(SuggestionFactory::class)) {
      $factory = new SuggestionFactory($user_input);
    }
    $search_api_index = $query
      ->getIndex();
    try {
      $this
        ->connect($search_api_index, '_query');
      $index = $this
        ->getAlgoliaIndex();
    } catch (\Exception $e) {
      $this
        ->getLogger()
        ->error('Failed to connect to Algolia index with suffix: @suffix, Error: @message', [
        '@message' => $e
          ->getMessage(),
        '@suffix' => '_query',
      ]);
      return $suggestions;
    }
    $algolia_options = [
      'attributesToRetrieve' => [
        'query',
      ],
      'analytics' => TRUE,
    ];
    try {
      $data = $index
        ->search($user_input, $algolia_options);
    } catch (\Exception $e) {
      $this
        ->getLogger()
        ->error('Failed to load autocomplete suggestions from Algolia. Query: @query, Error: @message', [
        '@message' => $e
          ->getMessage(),
        '@query' => $user_input,
      ]);
      return $suggestions;
    }
    foreach ($data['hits'] ?? [] as $row) {
      $suggestions[] = $factory
        ->createFromSuggestedKeys($row['query']);
    }
    return $suggestions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BackendPluginBase::$fieldsHelper protected property The fields helper.
BackendPluginBase::$messenger protected property The messenger. Overrides MessengerTrait::$messenger
BackendPluginBase::$server protected property The server this backend is configured for.
BackendPluginBase::$serverId protected property The backend's server's ID.
BackendPluginBase::addIndex public function Adds a new index to this server. Overrides BackendSpecificInterface::addIndex 2
BackendPluginBase::getBackendDefinedFields public function Provides information on additional fields made available by the backend. Overrides BackendSpecificInterface::getBackendDefinedFields
BackendPluginBase::getDiscouragedProcessors public function Limits the processors displayed in the UI for indexes on this server. Overrides BackendSpecificInterface::getDiscouragedProcessors 1
BackendPluginBase::getFieldsHelper public function Retrieves the fields helper.
BackendPluginBase::getMessenger public function Retrieves the messenger.
BackendPluginBase::getQueryFulltextFields protected function Retrieves the effective fulltext fields from the query.
BackendPluginBase::getServer public function Retrieves the server entity for this backend. Overrides BackendInterface::getServer
BackendPluginBase::getSpecialFields protected function Creates dummy field objects for the "magic" fields present for every index. 1
BackendPluginBase::isAvailable public function Returns a boolean with the availability of the backend. Overrides BackendSpecificInterface::isAvailable 1
BackendPluginBase::postInsert public function Reacts to the server's creation. Overrides BackendInterface::postInsert 1
BackendPluginBase::postUpdate public function Notifies the backend that its configuration was updated. Overrides BackendInterface::postUpdate 2
BackendPluginBase::preDelete public function Notifies the backend that the server is about to be deleted. Overrides BackendInterface::preDelete 1
BackendPluginBase::preUpdate public function Notifies the backend that its configuration is about to be updated. Overrides BackendInterface::preUpdate 1
BackendPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurablePluginBase::setConfiguration
BackendPluginBase::setFieldsHelper public function Sets the fields helper.
BackendPluginBase::setMessenger public function Sets the messenger. Overrides MessengerTrait::setMessenger
BackendPluginBase::setServer public function Sets the server entity for this backend. Overrides BackendInterface::setServer
BackendPluginBase::supportsDataType public function Determines whether the backend supports a given add-on data type. Overrides BackendSpecificInterface::supportsDataType 1
BackendPluginBase::updateIndex public function Notifies the server that an index attached to it has been changed. Overrides BackendSpecificInterface::updateIndex 2
BackendPluginBase::validateOperator protected function Verifies that the given condition operator is valid for this backend.
BackendPluginBase::__sleep public function Implements the magic __sleep() method. Overrides DependencySerializationTrait::__sleep 1
BackendPluginBase::__wakeup public function Implements the magic __wakeup() method. Overrides DependencySerializationTrait::__wakeup 1
ConfigurablePluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies 6
ConfigurablePluginBase::calculatePluginDependencies Deprecated protected function Calculates and adds dependencies of a specific plugin instance.
ConfigurablePluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ConfigurablePluginBase::getDescription public function Returns the plugin's description. Overrides ConfigurablePluginInterface::getDescription
ConfigurablePluginBase::getPluginDependencies Deprecated protected function Calculates and returns dependencies of a specific plugin instance.
ConfigurablePluginBase::label public function Returns the label for use on the administration pages. Overrides ConfigurablePluginInterface::label
ConfigurablePluginBase::moduleHandler Deprecated protected function Wraps the module handler.
ConfigurablePluginBase::onDependencyRemoval public function Informs the plugin that some of its dependencies are being removed. Overrides ConfigurablePluginInterface::onDependencyRemoval 5
ConfigurablePluginBase::themeHandler Deprecated protected function Wraps the theme handler.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
HideablePluginBase::isHidden public function Determines whether this plugin should be hidden in the UI. Overrides HideablePluginInterface::isHidden 1
LoggerTrait::logException protected function Logs an exception.
MessengerTrait::messenger public function Gets the messenger. 29
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginDependencyTrait::calculatePluginDependencies protected function Calculates and adds dependencies of a specific plugin instance. Aliased as: traitCalculatePluginDependencies 1
PluginDependencyTrait::getPluginDependencies protected function Calculates and returns dependencies of a specific plugin instance. Aliased as: traitGetPluginDependencies
PluginDependencyTrait::moduleHandler protected function Wraps the module handler. Aliased as: traitModuleHandler 1
PluginDependencyTrait::themeHandler protected function Wraps the theme handler. Aliased as: traitThemeHandler 1
PluginFormTrait::submitConfigurationForm public function Form submission handler. 7
PluginFormTrait::validateConfigurationForm public function Form validation handler. 2
SearchApiAlgoliaBackend::$algoliaClient protected property A connection to the Algolia server.
SearchApiAlgoliaBackend::$algoliaIndex protected property Algolia Index.
SearchApiAlgoliaBackend::$languageManager protected property The language manager.
SearchApiAlgoliaBackend::$logger protected property The logger to use for logging messages. Overrides LoggerTrait::$logger
SearchApiAlgoliaBackend::$moduleHandler protected property The module handler.
SearchApiAlgoliaBackend::alterAlgoliaObjects protected function Applies custom modifications to indexed Algolia objects.
SearchApiAlgoliaBackend::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
SearchApiAlgoliaBackend::connect protected function Creates a connection to the Algolia Search server as configured.
SearchApiAlgoliaBackend::create public static function Creates an instance of the plugin. Overrides BackendPluginBase::create
SearchApiAlgoliaBackend::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurablePluginBase::defaultConfiguration
SearchApiAlgoliaBackend::deleteAllIndexItems public function Deletes all the items from the index. Overrides BackendSpecificInterface::deleteAllIndexItems
SearchApiAlgoliaBackend::deleteItems public function Deletes the specified items from the index. Overrides BackendSpecificInterface::deleteItems
SearchApiAlgoliaBackend::extractConditions private function Extract conditions.
SearchApiAlgoliaBackend::extractFacetsData private function Extract facets data from response.
SearchApiAlgoliaBackend::getAlgolia public function Returns the AlgoliaSearch client.
SearchApiAlgoliaBackend::getAlgoliaIndex protected function Get the Algolia index.
SearchApiAlgoliaBackend::getApiKey protected function Get the API key (provided by Algolia).
SearchApiAlgoliaBackend::getApplicationId protected function Get the ApplicationID (provided by Algolia).
SearchApiAlgoliaBackend::getAutocompleteSuggestions public function Implements autocomplete compatible to AutocompleteBackendInterface.
SearchApiAlgoliaBackend::getLogger public function Retrieves the logger to use. Overrides LoggerTrait::getLogger
SearchApiAlgoliaBackend::getModuleHandler public function Returns the module handler to use for this plugin.
SearchApiAlgoliaBackend::getSupportedFeatures public function Returns all features that this backend supports. Overrides BackendPluginBase::getSupportedFeatures
SearchApiAlgoliaBackend::indexItem protected function Indexes a single item on the specified index.
SearchApiAlgoliaBackend::indexItems public function Indexes the specified items. Overrides BackendSpecificInterface::indexItems
SearchApiAlgoliaBackend::listIndexes public function Retrieves the list of available Algolia indexes.
SearchApiAlgoliaBackend::prepareItem protected function Prepares a single item for indexing.
SearchApiAlgoliaBackend::removeIndex public function Removes an index from this server. Overrides BackendPluginBase::removeIndex
SearchApiAlgoliaBackend::search public function Executes a search on this server. Overrides BackendSpecificInterface::search
SearchApiAlgoliaBackend::setAlgoliaIndex protected function Set the Algolia index.
SearchApiAlgoliaBackend::setLogger public function Sets the logger to use. Overrides LoggerTrait::setLogger
SearchApiAlgoliaBackend::setModuleHandler public function Sets the module handler to use for this plugin.
SearchApiAlgoliaBackend::viewSettings public function Returns additional, backend-specific information about this server. Overrides BackendPluginBase::viewSettings
SearchApiAlgoliaBackend::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides BackendPluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.