/** * Implements hook_node_search_result(). */ function {{ machine_name }}_node_search_result(\Drupal\node\NodeInterface $node) { $rating = \Drupal::database()->query('SELECT SUM([points]) FROM {my_rating} WHERE [nid] = :nid', ['nid' => $node->id()])->fetchField(); return ['rating' => \Drupal::translation()->formatPlural($rating, '1 point', '@count points')]; }