? 220143-fix-filter-url-rev2.patch ? 220143-fix-filter-url.patch ? 312930-speedup-search-update-totals.patch ? 336483-add-index-for-comment-count.patch ? 470306-email-column-too-short-rev4.patch ? modules/search/search.module-test Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.303 diff -u -p -r1.303 search.module --- modules/search/search.module 23 Jul 2009 20:58:26 -0000 1.303 +++ modules/search/search.module 29 Jul 2009 05:00:45 -0000 @@ -249,6 +249,11 @@ function search_reindex($sid = NULL, $ty } else { db_query("DELETE FROM {search_dataset} WHERE sid = %d AND type = '%s'", $sid, $type); + $result = db_query("SELECT word FROM {search_index} WHERE sid = %d AND type = '%s'", $sid, $type); + while ($row = db_fetch_object($result)) { + search_dirty($row->word); + } + db_query("DELETE FROM {search_index} WHERE sid = %d AND type = '%s'", $sid, $type); // Don't remove links if re-indexing. if (!$reindex) { @@ -296,16 +301,14 @@ function search_update_totals() { foreach (search_dirty() as $word => $dummy) { // Get total count $total = db_result(db_query("SELECT SUM(score) FROM {search_index} WHERE word = '%s'", $word)); - // Apply Zipf's law to equalize the probability distribution - $total = log10(1 + 1/(max(1, $total))); - db_merge('search_total')->key(array('word' => $word))->fields(array('count' => $total))->execute(); - } - // Find words that were deleted from search_index, but are still in - // search_total. We use a LEFT JOIN between the two tables and keep only the - // rows which fail to join. - $result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL"); - while ($word = db_fetch_object($result)) { - db_query("DELETE FROM {search_total} WHERE word = '%s'", $word->realword); + if (!$total) { + db_query("DELETE FROM {search_total} WHERE word = '%s'", $word); + } + else { + // Apply Zipf's law to equalize the probability distribution + $total = log10(1 + 1/(max(1, $total))); + db_merge('search_total')->key(array('word' => $word))->fields(array('count' => $total))->execute(); + } } }