diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2005-01-11 09:41:49 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2005-01-11 09:41:49 +0000 |
commit | 92bc08b5b926b3f8fba5c0cdfa74fe9c0ba8fe8b (patch) | |
tree | 1c3a9fbec8174e0bc4e3518263d4ebb7d13b3abd | |
parent | 410f3010060dcb5c25f7f52f6d96aeaa9915d8ef (diff) | |
download | brdo-92bc08b5b926b3f8fba5c0cdfa74fe9c0ba8fe8b.tar.gz brdo-92bc08b5b926b3f8fba5c0cdfa74fe9c0ba8fe8b.tar.bz2 |
- Make the search settings page more user-friendly.
-rw-r--r-- | modules/node.module | 5 | ||||
-rw-r--r-- | modules/node/node.module | 5 | ||||
-rw-r--r-- | modules/search.module | 63 | ||||
-rw-r--r-- | modules/search/search.module | 63 |
4 files changed, 80 insertions, 56 deletions
diff --git a/modules/node.module b/modules/node.module index d2615c1bc..58821bbc4 100644 --- a/modules/node.module +++ b/modules/node.module @@ -577,6 +577,11 @@ function node_search($op = 'search', $keys = null) { case 'reset': variable_del('node_cron_last'); return; + case 'status': + $last = variable_get('node_cron_last', 0); + $total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND moderate = 0')); + $remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last)); + return array('remaining' => $remaining, 'total' => $total); case 'search': $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1 AND '. node_access_where_sql()); $results = array(); diff --git a/modules/node/node.module b/modules/node/node.module index d2615c1bc..58821bbc4 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -577,6 +577,11 @@ function node_search($op = 'search', $keys = null) { case 'reset': variable_del('node_cron_last'); return; + case 'status': + $last = variable_get('node_cron_last', 0); + $total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND moderate = 0')); + $remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d) ORDER BY GREATEST(n.created, n.changed, c.last_comment_timestamp) ASC', $last, $last, $last)); + return array('remaining' => $remaining, 'total' => $total); case 'search': $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1 AND '. node_access_where_sql()); $results = array(); diff --git a/modules/search.module b/modules/search.module index bd90a9fcf..01da27b9b 100644 --- a/modules/search.module +++ b/modules/search.module @@ -51,8 +51,8 @@ function search_help($section = 'admin/help#search') { return t('Enables site-wide keyword searching.'); case 'admin/settings/search': return t(' -<p>The search engine works by maintaining an index of the words in your site\'s content. You can adjust the settings below to tweak the indexing behaviour. Note that the search requires cron to be set up correctly.</p> -<p>Changes to these settings will only apply to content that is indexed after the change. If you want them to apply to everything, you need to wipe the index with the button below.</p>'); +<p>The search engine works by maintaining an index of the words in your site\'s content. You can adjust the settings below to tweak the indexing behaviour.</p> +'); case 'search#noresults': return t('<p><ul> <li>Check if your spelling is correct.</li> @@ -104,28 +104,41 @@ function search_menu($may_cache) { */ function search_admin() { if ($_POST) { - system_settings_save(); - } - if ($_POST['op'] == t('Wipe index')) { - search_wipe(); - drupal_set_message(t('The search index has been wiped.')); - drupal_goto('admin/settings/search'); + if (variable_get('minimum_word_size', 3) != $_POST['edit']['minimum_word_size'] || + variable_get('remove_short', 3) != $_POST['edit']['remove_short']) { + // Note: ensure logical order of messages + system_settings_save(); + drupal_set_message(t('The index will be rebuilt.')); + search_wipe(); + } + else { + system_settings_save(); + } } + // Collect some stats + $remaining = 0; + $total = 0; + foreach (module_list() as $module) { + if (module_hook($module, 'search')) { + $status = module_invoke($module, 'search', 'status'); + $remaining += $status['remaining']; + $total += $status['total']; + } + } + $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%'; + $status = '<p><strong>'. t('%percentage of the site has been indexed. There are %count items left to index.', array('%percentage' => $percentage, '%count' => $remaining)) .'</strong></p>'; + $output = form_group('Indexing status', $status); + + // Indexing throttle: + $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500)); + $group = form_select(t('Items to index per cron run'), 'search_cron_limit', variable_get('search_cron_limit', 100), $items, t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.')); + $output .= form_group(t('Indexing throttle'), $group); // Indexing settings: - $group = form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 3), 3, 3, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.')); + $group = '<em>'. t('<p>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.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>'; + $group .= form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 3), 3, 3, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.')); $group .= form_textfield(t('Minimum word length to search for'), 'remove_short', variable_get('remove_short', 3), 3, 3, t('The number of characters a word has to be to be searched for, including wildcard characters.')); - $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500)); - $group .= form_select(t('Items to index per cron run'), 'search_cron_limit', variable_get('search_cron_limit', 100), $items, t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.')); - $output = form_group(t('Indexing settings'), $group); - - // Collect some stats - $estimate = variable_get('search_indexed', 0); - $nodes = max(1, db_result(db_query('SELECT COUNT(*) FROM {node}'))); - $percentage = ((int)min(100, 100 * $estimate / $nodes)) . '%'; - $status = '<p>'. t('Approximately %percentage of the site has been indexed.', array('%percentage' => $percentage)) .'</p>'; - $status .= '<p>'. form_button(t('Wipe index')) . '</p>'; - $output .= form_group('Indexing status', $status); + $output .= form_group(t('Indexing settings'), $group); print theme('page', system_settings_form($output)); } @@ -141,8 +154,6 @@ function search_admin() { */ function search_wipe($sid = NULL, $type = NULL) { if ($type == NULL && $sid == NULL) { - db_query('DELETE FROM {search_index}'); - db_query('DELETE FROM {search_total}'); module_invoke_all('search', 'reset'); } else { @@ -196,10 +207,6 @@ function search_cron() { while ($word = db_fetch_object($result)) { db_query("DELETE FROM {search_total} WHERE word = '%s'", $word->realword); } - - // Count indexed items (for administration screen) - $indexed = db_result(db_query('SELECT COUNT(DISTINCT sid) FROM {search_index}')); - variable_set('search_indexed', $indexed); } /** @@ -729,8 +736,8 @@ function search_excerpt($keys, $text) { /** * Helper function for array_walk in search_except. */ -function _search_excerpt_replace($text) { - return preg_quote($text, '/'); +function _search_excerpt_replace(&$text) { + $text = preg_quote($text, '/'); } /** diff --git a/modules/search/search.module b/modules/search/search.module index bd90a9fcf..01da27b9b 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -51,8 +51,8 @@ function search_help($section = 'admin/help#search') { return t('Enables site-wide keyword searching.'); case 'admin/settings/search': return t(' -<p>The search engine works by maintaining an index of the words in your site\'s content. You can adjust the settings below to tweak the indexing behaviour. Note that the search requires cron to be set up correctly.</p> -<p>Changes to these settings will only apply to content that is indexed after the change. If you want them to apply to everything, you need to wipe the index with the button below.</p>'); +<p>The search engine works by maintaining an index of the words in your site\'s content. You can adjust the settings below to tweak the indexing behaviour.</p> +'); case 'search#noresults': return t('<p><ul> <li>Check if your spelling is correct.</li> @@ -104,28 +104,41 @@ function search_menu($may_cache) { */ function search_admin() { if ($_POST) { - system_settings_save(); - } - if ($_POST['op'] == t('Wipe index')) { - search_wipe(); - drupal_set_message(t('The search index has been wiped.')); - drupal_goto('admin/settings/search'); + if (variable_get('minimum_word_size', 3) != $_POST['edit']['minimum_word_size'] || + variable_get('remove_short', 3) != $_POST['edit']['remove_short']) { + // Note: ensure logical order of messages + system_settings_save(); + drupal_set_message(t('The index will be rebuilt.')); + search_wipe(); + } + else { + system_settings_save(); + } } + // Collect some stats + $remaining = 0; + $total = 0; + foreach (module_list() as $module) { + if (module_hook($module, 'search')) { + $status = module_invoke($module, 'search', 'status'); + $remaining += $status['remaining']; + $total += $status['total']; + } + } + $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%'; + $status = '<p><strong>'. t('%percentage of the site has been indexed. There are %count items left to index.', array('%percentage' => $percentage, '%count' => $remaining)) .'</strong></p>'; + $output = form_group('Indexing status', $status); + + // Indexing throttle: + $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500)); + $group = form_select(t('Items to index per cron run'), 'search_cron_limit', variable_get('search_cron_limit', 100), $items, t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.')); + $output .= form_group(t('Indexing throttle'), $group); // Indexing settings: - $group = form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 3), 3, 3, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.')); + $group = '<em>'. t('<p>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.</p><p>The default settings should be appropriate for the majority of sites.</p>') .'</em>'; + $group .= form_textfield(t('Minimum word length to index'), 'minimum_word_size', variable_get('minimum_word_size', 3), 3, 3, t('The number of characters a word has to be to be indexed. Words shorter than this will not be searchable.')); $group .= form_textfield(t('Minimum word length to search for'), 'remove_short', variable_get('remove_short', 3), 3, 3, t('The number of characters a word has to be to be searched for, including wildcard characters.')); - $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500)); - $group .= form_select(t('Items to index per cron run'), 'search_cron_limit', variable_get('search_cron_limit', 100), $items, t('The maximum amount of items that will be indexed in one cron run. Set this number lower if your cron is timing out or if PHP is running out of memory.')); - $output = form_group(t('Indexing settings'), $group); - - // Collect some stats - $estimate = variable_get('search_indexed', 0); - $nodes = max(1, db_result(db_query('SELECT COUNT(*) FROM {node}'))); - $percentage = ((int)min(100, 100 * $estimate / $nodes)) . '%'; - $status = '<p>'. t('Approximately %percentage of the site has been indexed.', array('%percentage' => $percentage)) .'</p>'; - $status .= '<p>'. form_button(t('Wipe index')) . '</p>'; - $output .= form_group('Indexing status', $status); + $output .= form_group(t('Indexing settings'), $group); print theme('page', system_settings_form($output)); } @@ -141,8 +154,6 @@ function search_admin() { */ function search_wipe($sid = NULL, $type = NULL) { if ($type == NULL && $sid == NULL) { - db_query('DELETE FROM {search_index}'); - db_query('DELETE FROM {search_total}'); module_invoke_all('search', 'reset'); } else { @@ -196,10 +207,6 @@ function search_cron() { while ($word = db_fetch_object($result)) { db_query("DELETE FROM {search_total} WHERE word = '%s'", $word->realword); } - - // Count indexed items (for administration screen) - $indexed = db_result(db_query('SELECT COUNT(DISTINCT sid) FROM {search_index}')); - variable_set('search_indexed', $indexed); } /** @@ -729,8 +736,8 @@ function search_excerpt($keys, $text) { /** * Helper function for array_walk in search_except. */ -function _search_excerpt_replace($text) { - return preg_quote($text, '/'); +function _search_excerpt_replace(&$text) { + $text = preg_quote($text, '/'); } /** |