function NodeSearch::indexNode
Same name in other branches
- 9 core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexNode()
- 8.9.x core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexNode()
- 11.x core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexNode()
Indexes a single node.
Parameters
\Drupal\node\NodeInterface $node: The node to index.
Return value
array An array of words to update after indexing.
1 call to NodeSearch::indexNode()
- NodeSearch::updateIndex in core/
modules/ node/ src/ Plugin/ Search/ NodeSearch.php - Updates the search index for this plugin.
File
-
core/
modules/ node/ src/ Plugin/ Search/ NodeSearch.php, line 507
Class
- NodeSearch
- Handles searching for node entities using the Search module index.
Namespace
Drupal\node\Plugin\SearchCode
protected function indexNode(NodeInterface $node) {
$words = [];
$languages = $node->getTranslationLanguages();
$node_render = $this->entityTypeManager
->getViewBuilder('node');
foreach ($languages as $language) {
$node = $node->getTranslation($language->getId());
// Render the node.
$build = $node_render->view($node, 'search_index', $language->getId());
unset($build['#theme']);
// Add the title to text so it is searchable.
$build['search_title'] = [
'#prefix' => '<h1>',
'#plain_text' => $node->label(),
'#suffix' => '</h1>',
'#weight' => -1000,
];
$text = $this->renderer
->renderInIsolation($build);
// Fetch extra data normally not visible.
$extra = $this->moduleHandler
->invokeAll('node_update_index', [
$node,
]);
foreach ($extra as $t) {
$text .= $t;
}
// Update index, using search index "type" equal to the plugin ID.
$words += $this->searchIndex
->index($this->getPluginId(), $node->id(), $language->getId(), $text, FALSE);
}
return $words;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.