You are here

public function AutoIndexNodeSearch::indexSingleNode in Auto Index 8

Add a public method to allow us to target single nodes outside of this class.

Parameters

NodeInterface $node:

File

src/Plugin/Search/AutoIndexNodeSearch.php, line 21

Class

AutoIndexNodeSearch
The method we wish to call on the original object IndexNodeSearch has a protected visibility applied, and therefore we are left with 2 options. Copy and paste the current functionality into this module or extend the existing class. We are extending…

Namespace

Drupal\auto_index\Plugin\Search

Code

public function indexSingleNode(NodeInterface $node) {

  // Ensure the
  $query = db_select('node', 'n', array(
    'target' => 'replica',
  ));
  $query
    ->addField('n', 'nid');
  $query
    ->leftJoin('search_dataset', 'sd', 'sd.sid = n.nid AND sd.type = :type', array(
    ':type' => $this
      ->getPluginId(),
  ));
  $query
    ->condition($query
    ->andConditionGroup()
    ->condition('n.nid', $node
    ->id())
    ->condition($query
    ->orConditionGroup()
    ->where('sd.sid IS NULL')
    ->condition('sd.reindex', 0, '<>')));
  $num_rows = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($num_rows < 1) {
    return;
  }

  // Use the implementation of indexNode from the plugin.
  $this
    ->indexNode($node);

  // Register a shutdown hook to ensure the totals get recalculated.
  drupal_register_shutdown_function('search_update_totals');
}