search_cron
- Versions
- 4.6 – 7
search_cron()
Implementation of hook_cron().
Fires hook_update_index() in all modules and cleans up dirty words (see search_dirty).
Code
modules/search.module, line 207
<?php
function search_cron() {
// Update word index
foreach (module_list() as $module) {
module_invoke($module, 'update_index');
}
// Update word counts for new/changed words
foreach (search_dirty() as $word => $dummy) {
$total = db_result(db_query("SELECT SUM(score) FROM {search_index} WHERE word = '%s'", $word));
db_query("UPDATE {search_total} SET count = %d WHERE word = '%s'", $total, $word);
if (!db_affected_rows()) {
// Note: affected rows does not count matching rows that already had the right value!
$exists = db_result(db_query("SELECT COUNT(*) FROM {search_total} WHERE word = '%s'", $word));
if (!$exists) {
db_query("INSERT INTO {search_total} (word, count) VALUES ('%s', %d)", $word, $total);
}
}
}
// 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);
}
}
?>Login or register to post comments 