diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/node.module | 5 | ||||
-rw-r--r-- | modules/node/node.module | 5 | ||||
-rw-r--r-- | modules/search.module | 37 | ||||
-rw-r--r-- | modules/search/search.module | 37 |
4 files changed, 60 insertions, 24 deletions
diff --git a/modules/node.module b/modules/node.module index 501272ae2..1f2b24f0d 100644 --- a/modules/node.module +++ b/modules/node.module @@ -1409,6 +1409,9 @@ function node_delete($edit) { // Clear the cache so an anonymous poster can see the node being deleted. cache_clear_all(); + // Remove this node from the search index + search_wipe($node->nid, 'node'); + watchdog('special', t('%type: deleted %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>"))); $output = t('The node has been deleted.'); } @@ -1515,7 +1518,7 @@ function node_update_index() { $last = variable_get('node_cron_last', 0); $limit = (int)variable_get('search_cron_limit', 100); - $result = db_query_range('SELECT nid FROM {node} n WHERE n.status = 1 AND moderate = 0 AND (created > %d OR changed > %d) ORDER BY GREATEST(created, changed) ASC', $last, $last, 0, $limit); + $result = db_query_range('SELECT n.nid 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, 0, $limit); while ($node = db_fetch_object($result)) { $node = node_load(array('nid' => $node->nid)); diff --git a/modules/node/node.module b/modules/node/node.module index 501272ae2..1f2b24f0d 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1409,6 +1409,9 @@ function node_delete($edit) { // Clear the cache so an anonymous poster can see the node being deleted. cache_clear_all(); + // Remove this node from the search index + search_wipe($node->nid, 'node'); + watchdog('special', t('%type: deleted %title.', array('%type' => '<em>'. t($node->type) .'</em>', '%title' => "<em>$node->title</em>"))); $output = t('The node has been deleted.'); } @@ -1515,7 +1518,7 @@ function node_update_index() { $last = variable_get('node_cron_last', 0); $limit = (int)variable_get('search_cron_limit', 100); - $result = db_query_range('SELECT nid FROM {node} n WHERE n.status = 1 AND moderate = 0 AND (created > %d OR changed > %d) ORDER BY GREATEST(created, changed) ASC', $last, $last, 0, $limit); + $result = db_query_range('SELECT n.nid 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, 0, $limit); while ($node = db_fetch_object($result)) { $node = node_load(array('nid' => $node->nid)); diff --git a/modules/search.module b/modules/search.module index 7bddc7285..27ecb0ba9 100644 --- a/modules/search.module +++ b/modules/search.module @@ -47,8 +47,10 @@ function search_help($section = 'admin/help#search') { switch ($section) { case 'admin/modules#description': return t('Enables site-wide keyword searching.'); - case 'admin/search': - return t('<p>The search engine works by maintaining an index of words in your site\'s content. You can adjust the settings below to tweak the indexing behaviour. Note that indexing 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>'); + 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>'); case 'search#noresults': return t('<p><ul> <li>Check if your spelling is correct.</li> @@ -97,6 +99,7 @@ function search_menu($may_cache) { 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'admin/settings/search', 'title' => t('search'), 'callback' => 'search_admin', + 'type' => MENU_NORMAL_ITEM, 'access' => user_access('administer site configuration')); } @@ -112,6 +115,8 @@ function search_admin() { } if ($_POST['op'] == t('Wipe index')) { search_wipe(); + drupal_set_message(t('The search index has been wiped.')); + drupal_goto('admin/settings/search'); } // Indexing settings: @@ -133,15 +138,25 @@ function search_admin() { } /** - * Wipe the search index. + * Wipes a part of or the entire search index. + * + * @param $sid + * (optional) The SID of the item to wipe. If specified, $type must be passed + * too. + * @param $type + * (optional) The type of item to wipe. + * */ -function search_wipe() { - db_query('DELETE FROM {search_index}'); - db_query('DELETE FROM {search_total}'); - module_invoke_all('search', 'reset'); - - drupal_set_message(t('The search index has been wiped.')); - drupal_goto('admin/settings/search'); +function search_wipe($type = NULL, $sid = NULL) { + if ($type == NULL && $sid == NULL) { + db_query('DELETE FROM {search_index}'); + db_query('DELETE FROM {search_total}'); + module_invoke_all('search', 'reset'); + } + else { + db_query("DELETE FROM {search_index} WHERE sid = %d AND type = '%s'", $sid, $type); + db_query("DELETE FROM {search_index} WHERE fromsid = %d AND fromtype = '%s'", $sid, $type); + } } /** @@ -356,7 +371,7 @@ function search_index($sid, $type, $text) { $tag = !$tag; } - db_query("DELETE FROM {search_index} WHERE sid = %d AND type = '%s'", $sid, $type); + search_wipe($sid, $type); // Insert results into search index foreach ($results[0] as $word => $score) { diff --git a/modules/search/search.module b/modules/search/search.module index 7bddc7285..27ecb0ba9 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -47,8 +47,10 @@ function search_help($section = 'admin/help#search') { switch ($section) { case 'admin/modules#description': return t('Enables site-wide keyword searching.'); - case 'admin/search': - return t('<p>The search engine works by maintaining an index of words in your site\'s content. You can adjust the settings below to tweak the indexing behaviour. Note that indexing 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>'); + 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>'); case 'search#noresults': return t('<p><ul> <li>Check if your spelling is correct.</li> @@ -97,6 +99,7 @@ function search_menu($may_cache) { 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'admin/settings/search', 'title' => t('search'), 'callback' => 'search_admin', + 'type' => MENU_NORMAL_ITEM, 'access' => user_access('administer site configuration')); } @@ -112,6 +115,8 @@ function search_admin() { } if ($_POST['op'] == t('Wipe index')) { search_wipe(); + drupal_set_message(t('The search index has been wiped.')); + drupal_goto('admin/settings/search'); } // Indexing settings: @@ -133,15 +138,25 @@ function search_admin() { } /** - * Wipe the search index. + * Wipes a part of or the entire search index. + * + * @param $sid + * (optional) The SID of the item to wipe. If specified, $type must be passed + * too. + * @param $type + * (optional) The type of item to wipe. + * */ -function search_wipe() { - db_query('DELETE FROM {search_index}'); - db_query('DELETE FROM {search_total}'); - module_invoke_all('search', 'reset'); - - drupal_set_message(t('The search index has been wiped.')); - drupal_goto('admin/settings/search'); +function search_wipe($type = NULL, $sid = NULL) { + if ($type == NULL && $sid == NULL) { + db_query('DELETE FROM {search_index}'); + db_query('DELETE FROM {search_total}'); + module_invoke_all('search', 'reset'); + } + else { + db_query("DELETE FROM {search_index} WHERE sid = %d AND type = '%s'", $sid, $type); + db_query("DELETE FROM {search_index} WHERE fromsid = %d AND fromtype = '%s'", $sid, $type); + } } /** @@ -356,7 +371,7 @@ function search_index($sid, $type, $text) { $tag = !$tag; } - db_query("DELETE FROM {search_index} WHERE sid = %d AND type = '%s'", $sid, $type); + search_wipe($sid, $type); // Insert results into search index foreach ($results[0] as $word => $score) { |