Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1033 diff -u -p -r1.1033 node.module --- modules/node/node.module 26 Mar 2009 13:31:25 -0000 1.1033 +++ modules/node/node.module 3 Apr 2009 01:54:39 -0000 @@ -1400,8 +1400,8 @@ function node_search($op = 'search', $ke return; case 'status': - $total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1')); - $remaining = db_result(db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND d.sid IS NULL OR d.reindex <> 0")); + $total = db_query('SELECT COUNT(nid) FROM {node} WHERE status = 1')->fetchField(); + $remaining = db_query("SELECT COUNT(n.nid) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND (d.sid IS NULL OR d.reindex <> 0)")->fetchField(); return array('remaining' => $remaining, 'total' => $total); case 'admin': @@ -1944,7 +1944,7 @@ function node_feed($nids = FALSE, $chann $item->body = $content; unset($item->teaser); } - + // Allow modules to modify the fully-built node. node_invoke_node($item, 'alter', $teaser, FALSE); } Index: modules/search/search.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.admin.inc,v retrieving revision 1.8 diff -u -p -r1.8 search.admin.inc --- modules/search/search.admin.inc 11 Jan 2009 21:19:18 -0000 1.8 +++ modules/search/search.admin.inc 3 Apr 2009 01:54:40 -0000 @@ -10,19 +10,24 @@ * Menu callback: confirm wiping of the index. */ function search_wipe_confirm() { - return confirm_form(array(), t('Are you sure you want to re-index the site?'), - 'admin/settings/search', t(' The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed. This action cannot be undone.'), t('Re-index site'), t('Cancel')); + return confirm_form( + array(), + t("Are you sure you want to reset your site's search index?"), + 'admin/settings/search', + t("Your site's search will continue to work, but no new content will show up in search results until all the existing content has been re-indexed by cron.") . ' ' . t('This action cannot be undone'), + t('Reset index'), + t('Cancel') + ); } /** * Handler for wipe confirmation */ -function search_wipe_confirm_submit(&$form, &$form_state) { +function search_wipe_confirm_submit($form, $form_state) { if ($form['confirm']) { search_wipe(); - drupal_set_message(t('The index will be rebuilt.')); + drupal_set_message(t('The search index will be rebuilt the next time cron is run.')); $form_state['redirect'] = 'admin/settings/search'; - return; } } @@ -34,43 +39,12 @@ function search_wipe_confirm_submit(&$fo * @see search_admin_settings_validate() */ function search_admin_settings() { - // Collect some stats - $remaining = 0; - $total = 0; - foreach (module_implements('search') as $module) { - $function = $module . '_search'; - $status = $function('status'); - $remaining += $status['remaining']; - $total += $status['total']; - } - $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.'); - $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%'; - $status = '

' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '

'; - $form['status'] = array('#type' => 'fieldset', '#title' => t('Indexing status')); - $form['status']['status'] = array('#markup' => $status); - $form['status']['wipe'] = array('#type' => 'submit', '#value' => t('Re-index site')); - - $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500)); - - // Indexing throttle: - $form['indexing_throttle'] = array( - '#type' => 'fieldset', - '#title' => t('Indexing throttle') - ); - $form['indexing_throttle']['search_cron_limit'] = array( - '#type' => 'select', - '#title' => t('Number of items to index per cron run'), - '#default_value' => 100, - '#options' => $items, - '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))) - ); - // Indexing settings: $form['indexing_settings'] = array( '#type' => 'fieldset', - '#title' => t('Indexing settings') + '#title' => t('Indexing settings'), ); $form['indexing_settings']['info'] = array( - '#markup' => t('

Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.

The default settings should be appropriate for the majority of sites.

') + '#markup' => '

' . t("Changing any of these settings will cause your site's search index to be reset.") . ' ' . t("Your site's search will continue to work, but no new content will show up in search results until all the existing content has been re-indexed by cron.") . '

', ); $form['indexing_settings']['minimum_word_size'] = array( '#type' => 'textfield', @@ -78,33 +52,52 @@ function search_admin_settings() { '#default_value' => 3, '#size' => 5, '#maxlength' => 3, - '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).') + '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).'), ); $form['indexing_settings']['overlap_cjk'] = array( '#type' => 'checkbox', '#title' => t('Simple CJK handling'), '#default_value' => TRUE, - '#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.') + '#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.'), + ); + $form['indexing_settings']['wipe'] = array( + '#type' => 'submit', + '#value' => t('Reset search index'), + '#submit' => array('search_admin_settings_submit_wipe'), ); - $form['#validate'] = array('search_admin_settings_validate'); + $form['indexing_throttle'] = array( + '#type' => 'fieldset', + '#title' => t('Indexing throttle') + ); + $form['indexing_throttle']['search_cron_limit'] = array( + '#type' => 'select', + '#title' => t('Number of items to index per cron run'), + '#default_value' => 100, + '#options' => drupal_map_assoc(array(10, 20, 50, 100, 200, 500)), + '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))), + ); - // Per module settings + // Add any module-specific search settings. $form = array_merge($form, module_invoke_all('search', 'admin')); - return system_settings_form($form, TRUE); + + return system_settings_form($form); +} + +function search_admin_settings_submit_wipe($form, $form_state) { + drupal_goto('admin/settings/search/wipe'); } /** - * Validate callback. + * Submit callback. */ -function search_admin_settings_validate($form, &$form_state) { - if ($form_state['values']['op'] == t('Re-index site')) { - drupal_goto('admin/settings/search/wipe'); - } - // If these settings change, the index needs to be rebuilt. - if ((variable_get('minimum_word_size', 3) != $form_state['values']['minimum_word_size']) || - (variable_get('overlap_cjk', TRUE) != $form_state['values']['overlap_cjk'])) { - drupal_set_message(t('The index will be rebuilt.')); - search_wipe(); +function search_admin_settings_submit($form, $form_state) { + // If any settings are changed, the index needs to be wiped. + foreach ($form_state['values'] as $variable => $value) { + $current = variable_get($variable); + if (isset($current) && $current != $value) { + drupal_set_message(t('Since you have changed search settings, your search index will be rebuilt on the next cron run.')); + search_wipe(); + } } } Index: modules/search/search.install =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.install,v retrieving revision 1.19 diff -u -p -r1.19 search.install --- modules/search/search.install 15 Nov 2008 13:01:09 -0000 1.19 +++ modules/search/search.install 3 Apr 2009 01:54:40 -0000 @@ -22,6 +22,36 @@ function search_uninstall() { } /** + * Implementation of hook_enable(). + */ +function search_enable() { + search_cron(); +} + +/** + * Implementation of hook_requirements. + */ +function search_requirements($phase) { + $requirements = array(); + $t = get_t(); + + if ($phase == 'runtime') { + $status = search_get_status(); + $requirements['search_index'] = array( + 'title' => $t('Search index'), + 'value' => $status['percentage'], + ); + if ($status['remaining']) { + $requirements['search_index']['description'] = $t('Search may not return some results because some content has yet to be indexed with cron.'); + $requirements['search_index']['description'] .= ' ' . $t('You can run cron to manually perform indexing.', array('@cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination())))); + $requirements['search_index']['severity'] = REQUIREMENT_WARNING; + } + } + + return $requirements; +} + +/** * Implementation of hook_schema(). */ function search_schema() { Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.287 diff -u -p -r1.287 search.module --- modules/search/search.module 27 Mar 2009 00:16:16 -0000 1.287 +++ modules/search/search.module 3 Apr 2009 01:54:41 -0000 @@ -90,10 +90,45 @@ define('PREG_CLASS_PUNCTUATION', define('PREG_CLASS_CJK', '\x{3041}-\x{30ff}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}' . '\x{4e00}-\x{9fbb}\x{f900}-\x{fad9}'); +function search_get_status($reset = FALSE) { + static $status; + + if (!isset($status) || $reset) { + $status = array( + 'remaining' => 0, + 'total' => 0, + ); + foreach (module_implements('search') as $module) { + $function = $module . '_search'; + $module_status = $function('status'); + $status['remaining'] += $module_status['remaining']; + $status['total'] += $module_status['total']; + } + $status['percentage'] = round(100 * ($status['total'] - $status['remaining']) / max(1, $status['total'])) . '%'; + //$status['percentage'] = round(min(100, 100 * ($status['total'] - $status['remaining']) / max(1, $status['total']))) . '%'; + } + + return $status; +} + +function search_check_status() { + $status = search_get_status(); + if ($status['remaining']) { + $message = t("Search may not return some results because only %percentage of the site's content has been indexed.", array('%percentage' => $status['percentage'])); + if (user_access('administer site configuration')) { + $message .= ' ' . t('You can run cron to manually perform indexing.', array('@cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination())))); + } + drupal_set_message($message, 'warning'); + } +} + /** * Implementation of hook_help(). */ function search_help($path, $arg) { + if ($arg[0] == 'search' && user_access('administer search')) { + search_check_status(); + } switch ($path) { case 'admin/help#search': $output = '

' . t('The search module adds the ability to search for content by keywords. Search is often the only practical way to find content on a large site, and is useful for finding both users and posts.') . '

'; @@ -101,7 +136,8 @@ function search_help($path, $arg) { $output .= '

' . t('For more information, see the online handbook entry for Search module.', array('@search' => 'http://drupal.org/handbook/modules/search/')) . '

'; return $output; case 'admin/settings/search': - return '

' . t('The search engine maintains an index of words found in your site\'s content. To build and maintain this index, a correctly configured cron maintenance task is required. Indexing behavior can be adjusted using the settings below.', array('@cron' => url('admin/reports/status'))) . '

'; + search_check_status(); + return '

' . t('The search engine maintains an index of words found in your site\'s content. To build and maintain this index, a correctly configured cron maintenance task is required.', array('@cron' => url('admin/reports/status'))) . '

'; case 'search#noresults': return t('