function search_api_acquia_cron_optimize in Acquia Search for Search API 7.2
Runs optimize during cron runs.
See also
1 call to search_api_acquia_cron_optimize()
- search_api_acquia_cron in ./
search_api_acquia.module - Implements hook_cron().
File
- ./
search_api_acquia.module, line 442 - Provides integration between your Drupal site and Acquia's hosted search service via the Search API Solr module.
Code
function search_api_acquia_cron_optimize() {
$action = variable_get('search_api_acquia_cron_action', 'spellcheck');
// We treat all unknown action settings as "none". However, we turn a blind
// eye for Britons and other people who can spell.
if (!in_array($action, array(
'spellcheck',
'optimize',
'optimise',
))) {
return;
}
// 86400 seconds is one day. We use slightly less here to allow for some
// variation in the request time of the cron run, so that the time of day will
// (more or less) stay the same.
if (REQUEST_TIME - variable_get('search_api_acquia_last_optimize', 0) > 86340) {
variable_set('search_api_acquia_last_optimize', REQUEST_TIME);
$conditions = array(
'class' => 'acquia_search_service',
'enabled' => TRUE,
);
$count = 0;
foreach (search_api_server_load_multiple(FALSE, $conditions) as $server) {
try {
$solr = $server
->getSolrConnection();
if ($action != 'spellcheck') {
$solr
->optimize(FALSE);
}
else {
$params['rows'] = 0;
$params['spellcheck'] = 'true';
$params['spellcheck.build'] = 'true';
$solr
->search(NULL, $params);
}
++$count;
} catch (SearchApiException $e) {
watchdog_exception('search_api_acquia', $e, '%type while optimizing Solr server @server: !message in %function (line %line of %file).', array(
'@server' => $server->name,
));
}
}
if ($count) {
$vars['@count'] = $count;
if ($action != 'spellcheck') {
watchdog('search_api_acquia', 'Optimized @count Solr server(s).', $vars, WATCHDOG_INFO);
}
else {
watchdog('search_api_acquia', 'Rebuilt spellcheck dictionary on @count Solr server(s).', $vars, WATCHDOG_INFO);
}
}
}
}