0

On exploring search_api.module file, there mentioned few hooks.Is there any practical demonstration how to use search_api_index_reindex hook?

Basically I'm trying to re-index nodes, after executing some operations. I tried the way, mentioned below, but didn't get any success. any help is really appreciated.

$conditions = [
    'status' => TRUE,
  ];
  $index_storage = \Drupal::entityTypeManager()->getStorage('search_api_index');
  $indexes = $index_storage->loadByProperties($conditions);
  foreach ($indexes as $index_id => $index) {
    try {
          $num = $index->indexItems('-1');
         // print_r($num);
          \Drupal::logger('Reindexing processing...')->debug(print('reindexing done'));
    }catch (Exception $e) {
\Drupal::logger('custom benefits cron reindexing')->debug(print($e));
    }
  }
  • You need to invalidate the index so it gets rebuilt, but that won't happen right away, only on a series of cron runs. – Alfred Armstrong Aug 1 '18 at 9:37
  • series of cron are set by increment of 1 hour. So, it means I have to wait for the last cron so that my data first get rebuilt? Is there any other alternative to re-index these nodes manually? – Sugandh Khanna Aug 1 '18 at 9:43
  • Manually? From the admin panel or using drush.drushcommands.com/drush-8x/search-api – Alfred Armstrong Aug 1 '18 at 9:52
  • Did you try this way? – Jonh Aug 1 '18 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.