diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index a6230f2..bbbb01a 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1349,7 +1349,7 @@ function comment_node_predelete(Node $node) { /** * Implements hook_node_update_index(). */ -function comment_node_update_index(Node $node) { +function comment_node_update_index(Node $node, $langcode) { $index_comments = &drupal_static(__FUNCTION__); if ($index_comments === NULL) { @@ -1377,7 +1377,7 @@ function comment_node_update_index(Node $node) { if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); comment_prepare_thread($comments); - $build = comment_view_multiple($comments, $node); + $build = comment_view_multiple($comments, $node, $langcode); return drupal_render($build); } } diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 9719fc0..ae4fac3 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -722,13 +722,15 @@ function hook_node_update(Drupal\node\Node $node) { * * @param Drupal\node\Node $node * The node being indexed. + * @param $langcode + * Language code of the variant of the node being indexed. * * @return string * Additional node information to be indexed. * * @ingroup node_api_hooks */ -function hook_node_update_index(Drupal\node\Node $node) { +function hook_node_update_index(Drupal\node\Node $node, $langcode) { $text = ''; $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED)); foreach ($comments as $comment) { diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 42d968d..8d7d36f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2630,21 +2630,23 @@ function _node_index_node(Node $node) { // results half-life calculation. variable_set('node_cron_last', $node->changed); - // Render the node. - $build = node_view($node, 'search_index'); - unset($build['#theme']); - $node->rendered = drupal_render($build); + foreach ($node->translations() as $language) { + // Render the node in this language. + $build = node_view($node, 'search_index', $language->langcode); + unset($build['#theme']); + $node->rendered = drupal_render($build); - $text = '

' . check_plain($node->title) . '

' . $node->rendered; + $text = '

' . check_plain($node->label($language->langcode)) . '

' . $node->rendered; - // Fetch extra data normally not visible - $extra = module_invoke_all('node_update_index', $node); - foreach ($extra as $t) { - $text .= $t; - } + // Fetch extra data normally not visible. + $extra = module_invoke_all('node_update_index', $node, $language->langcode); + foreach ($extra as $t) { + $text .= $t; + } - // Update index - search_index($node->nid, 'node', $text); + // Update index. + search_index($node->nid, 'node', $text, $langcode); + } } /** diff --git a/core/modules/search/search.install b/core/modules/search/search.install index c450f05..803f5bd 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -28,6 +28,12 @@ function search_schema() { 'default' => 0, 'description' => 'Search item ID, e.g. node ID for nodes.', ), + 'langcode' => array( + 'type' => 'varchar', + 'length' => '12', + 'not null' => TRUE, + 'description' => 'The {languages}.langcode of the item variant.', + ), 'type' => array( 'type' => 'varchar', 'length' => 16, @@ -48,7 +54,7 @@ function search_schema() { 'description' => 'Set to force node reindexing.', ), ), - 'primary key' => array('sid', 'type'), + 'primary key' => array('sid', 'langcode', 'type'), ); $schema['search_index'] = array( @@ -68,6 +74,12 @@ function search_schema() { 'default' => 0, 'description' => 'The {search_dataset}.sid of the searchable item to which the word belongs.', ), + 'langcode' => array( + 'type' => 'varchar', + 'length' => '12', + 'not null' => TRUE, + 'description' => 'The {languages}.langcode of the item variant.', + ), 'type' => array( 'type' => 'varchar', 'length' => 16, @@ -81,7 +93,7 @@ function search_schema() { ), ), 'indexes' => array( - 'sid_type' => array('sid', 'type'), + 'sid_type' => array('sid', 'langcode', 'type'), ), 'foreign keys' => array( 'search_dataset' => array( @@ -92,7 +104,7 @@ function search_schema() { ), ), ), - 'primary key' => array('word', 'sid', 'type'), + 'primary key' => array('word', 'sid', 'langcode', 'type'), ); $schema['search_total'] = array( diff --git a/core/modules/search/search.module b/core/modules/search/search.module index f567dae..72f84a2 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -315,20 +315,33 @@ function _search_menu_access($name) { * @param $module * (optional) The machine-readable name of the module for the item to remove * from the search index. + * @param $reindex + * (optional) Boolean to specify whether reindexing happens. + * @param $langcode + * (optional) Language code for the operation. If not provided, all + * index records for the $sid will be deleted. */ -function search_reindex($sid = NULL, $module = NULL, $reindex = FALSE) { +function search_reindex($sid = NULL, $module = NULL, $reindex = FALSE, $langcode = NULL) { if ($module == NULL && $sid == NULL) { module_invoke_all('search_reset'); } else { - db_delete('search_dataset') + $query = db_delete('search_dataset') ->condition('sid', $sid) - ->condition('type', $module) - ->execute(); - db_delete('search_index') + ->condition('type', $module); + if (!empty($langcode)) { + $query->condition('langcode', $langcode); + } + $query->execute(); + + $query = db_delete('search_index') ->condition('sid', $sid) - ->condition('type', $module) - ->execute(); + ->condition('type', $module); + if (!empty($langcode)) { + $query->condition('langcode', $langcode); + } + $query->execute(); + // Don't remove links if re-indexing. if (!$reindex) { db_delete('search_node_links') @@ -557,10 +570,12 @@ function search_invoke_preprocess(&$text) { * that implements hook_search_info()). * @param $text * The content of this item. Must be a piece of HTML or plain text. + * @param $langcode + * Language code for text being indexed. * * @ingroup search */ -function search_index($sid, $module, $text) { +function search_index($sid, $module, $text, $langcode) { $minimum_word_size = variable_get('minimum_word_size', 3); // Link matching @@ -701,12 +716,13 @@ function search_index($sid, $module, $text) { $tag = !$tag; } - search_reindex($sid, $module, TRUE); + search_reindex($sid, $module, TRUE, $langcode); // Insert cleaned up data into dataset db_insert('search_dataset') ->fields(array( 'sid' => $sid, + 'langcode' => $langcode, 'type' => $module, 'data' => $accum, 'reindex' => 0, @@ -722,6 +738,7 @@ function search_index($sid, $module, $text) { ->key(array( 'word' => $word, 'sid' => $sid, + 'langcode' => $langcode, 'type' => $module, )) ->fields(array('score' => $score))