Pull merge.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / update_index.twig
1 /**
2  * Implements hook_update_index().
3  */
4 function {{ machine_name }}_update_index() {
5   $limit = (int)variable_get('search_cron_limit', 100);
6
7   $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
8
9   foreach ($result as $node) {
10     $node = node_load($node->nid);
11
12     // Save the changed time of the most recent indexed node, for the search
13     // results half-life calculation.
14     variable_set('node_cron_last', $node->changed);
15
16     // Render the node.
17     node_build_content($node, 'search_index');
18     $node->rendered = drupal_render($node->content);
19
20     $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered;
21
22     // Fetch extra data normally not visible
23     $extra = module_invoke_all('node_update_index', $node);
24     foreach ($extra as $t) {
25       $text .= $t;
26     }
27
28     // Update index
29     search_index($node->nid, 'node', $text);
30   }
31 }