You are here

search_api_algolia.api.php in Search API Algolia 8

Same filename and directory in other branches
  1. 3.0.x search_api_algolia.api.php
  2. 2.0.x search_api_algolia.api.php

Hooks provided by the Search API Algolia search module.

File

search_api_algolia.api.php
View source
<?php

/**
 * @file
 * Hooks provided by the Search API Algolia search module.
 */
use Drupal\search_api\IndexInterface;

/**
 * @addtogroup hooks
 * @{
 */

/**
 * Alter Algolia objects before they are sent to Algolia for indexing.
 *
 * @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 \Drupal\search_api\Item\ItemInterface[] $items
 *   An array of items to be indexed, keyed by their item IDs.
 */
function hook_search_api_algolia_objects_alter(array &$objects, \Drupal\search_api\IndexInterface $index, array $items) {

  // Adds a "foo" field with value "bar" to all documents.
  foreach ($objects as $key => $object) {
    $objects[$key]['foo'] = 'bar';
  }
}

/**
 * Allow other modules to remove sorts handled in index rankings.
 *
 * @param array $sorts
 *   Sorts from query.
 * @param \Drupal\search_api\IndexInterface $index
 *   Index.
 */
function hook_search_api_algolia_sorts_alter(array &$sorts, IndexInterface $index) {
  unset($sorts['stock']);
}

/**
 * @} End of "addtogroup hooks".
 */

Functions

Namesort descending Description
hook_search_api_algolia_objects_alter Alter Algolia objects before they are sent to Algolia for indexing.
hook_search_api_algolia_sorts_alter Allow other modules to remove sorts handled in index rankings.