Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NodeSearch.php

function NodeSearch::updateIndex

Overrides SearchIndexingInterface::updateIndex

File

core/modules/node/src/Plugin/Search/NodeSearch.php, line 460

Class

NodeSearch
Handles searching for node entities using the Search module index.

Namespace

Drupal\node\Plugin\Search

Code

public function updateIndex() {
    // Interpret the cron limit setting as the maximum number of nodes to index
    // per cron run.
    $limit = (int) $this->searchSettings
        ->get('index.cron_limit');
    $query = $this->databaseReplica
        ->select('node', 'n');
    $query->addField('n', 'nid');
    $query->leftJoin('search_dataset', 'sd', '[sd].[sid] = [n].[nid] AND [sd].[type] = :type', [
        ':type' => $this->getPluginId(),
    ]);
    $query->addExpression('CASE MAX([sd].[reindex]) WHEN NULL THEN 0 ELSE 1 END', 'ex');
    $query->addExpression('MAX([sd].[reindex])', 'ex2');
    $query->condition($query->orConditionGroup()
        ->where('[sd].[sid] IS NULL')
        ->condition('sd.reindex', 0, '<>'));
    $query->orderBy('ex', 'DESC')
        ->orderBy('ex2')
        ->orderBy('n.nid')
        ->groupBy('n.nid')
        ->range(0, $limit);
    $nids = $query->execute()
        ->fetchCol();
    if (!$nids) {
        return;
    }
    $node_storage = $this->entityTypeManager
        ->getStorage('node');
    $words = [];
    try {
        foreach ($node_storage->loadMultiple($nids) as $node) {
            $words += $this->indexNode($node);
        }
    } finally {
        $this->searchIndex
            ->updateWordWeights($words);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal