apachesolr_cron()Implementation of hook_cron().
contributions/apachesolr/apachesolr.module, line 433
<?php
function apachesolr_cron() {
try {
$solr = apachesolr_get_solr();
// Check for unpublished content that wasn't deleted from the index.
$result = db_query("SELECT n.nid, n.status FROM {apachesolr_search_node} asn INNER JOIN {node} n ON n.nid = asn.nid WHERE asn.status != n.status");
while ($node = db_fetch_object($result)) {
_apachesolr_nodeapi_update($node, FALSE);
}
// Check for deleted content that wasn't deleted from the index.
$result = db_query("SELECT asn.nid FROM {apachesolr_search_node} asn LEFT JOIN {node} n ON n.nid = asn.nid WHERE n.nid IS NULL");
while ($node = db_fetch_object($result)) {
_apachesolr_nodeapi_delete($node, FALSE);
}
// Optimize the index (by default once a day).
$optimize_interval = variable_get('apachesolr_optimize_interval', 60 * 60 * 24);
$last = variable_get('apachesolr_last_optimize', 0);
$time = time();
if ($optimize_interval && ($time - $last > $optimize_interval)) {
$solr->optimize(FALSE, FALSE);
variable_set('apachesolr_last_optimize', $time);
apachesolr_index_updated($time);
}
// Only clear the cache if the index changed.
// TODO: clear on some schedule if running multi-site.
$updated = apachesolr_index_updated();
if ($updated) {
$solr->clearCache();
// Re-populate the luke cache.
$solr->getLuke();
// TODO: an admin interface for setting this. Assume for now 5 minutes.
if ($time - $updated >= variable_get('apachesolr_cache_delay', 300)) {
// Clear the updated flag.
apachesolr_index_updated(FALSE);
}
}
}
catch (Exception $e) {
watchdog('Apache Solr', nl2br(check_plain($e->getMessage())) .' in apachesolr_cron', WATCHDOG_ERROR);
}
}
?>