function apachesolr_index_node_check_table in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.index.inc \apachesolr_index_node_check_table()
- 6.3 apachesolr.index.inc \apachesolr_index_node_check_table()
hook_cron() helper to try to make the index table consistent with their respective entity table.
2 string references to 'apachesolr_index_node_check_table'
- apachesolr_entity_info_alter in ./
apachesolr.module - Implements hook_entity_info_alter().
- hook_apachesolr_entity_info_alter in ./
apachesolr.api.php - Add information to index other entities. There are some modules in http://drupal.org that can give a good example of custom entity indexing such as apachesolr_user, apachesolr_term
File
- ./
apachesolr.index.inc, line 1413 - Functions related to Apache Solr indexing operations.
Code
function apachesolr_index_node_check_table() {
// Check for unpublished content that wasn't deleted from the index.
$table = apachesolr_get_indexer_table('node');
// We do not check more nodes than double the cron limit per time
// Update or delete at most this many in each Solr query.
$limit = variable_get('apachesolr_cron_mass_limit', 500);
$query = db_select($table, 'aie')
->fields('n', array(
'nid',
'status',
))
->where('aie.status <> n.status')
->range(0, $limit * 2)
->addTag('apachesolr_index_node');
$query
->innerJoin('node', 'n', 'n.nid = aie.entity_id');
$nodes = $query
->execute()
->fetchAllAssoc('nid');
$node_lists = array_chunk($nodes, $limit, TRUE);
foreach ($node_lists as $nodes) {
watchdog('Apache Solr', 'On cron running apachesolr_nodeapi_mass_update() on nids @nids', array(
'@nids' => implode(',', array_keys($nodes)),
), WATCHDOG_NOTICE);
if (!apachesolr_index_nodeapi_mass_update($nodes, $table)) {
// Solr query failed - so stop trying.
break;
}
}
// Check for deleted content that wasn't deleted from the index.
$query = db_select($table, 'aien')
->isNull('n.nid')
->range(0, $limit * 2);
$query
->addExpression('aien.entity_id', 'nid');
$query
->leftJoin('node', 'n', 'n.nid = aien.entity_id');
$nodes = $query
->execute()
->fetchAllAssoc('nid');
$node_lists = array_chunk($nodes, $limit, TRUE);
foreach ($node_lists as $nodes) {
watchdog('Apache Solr', 'On cron running apachesolr_nodeapi_mass_delete() on nids @nids', array(
'@nids' => implode(',', array_keys($nodes)),
), WATCHDOG_NOTICE);
if (!apachesolr_index_nodeapi_mass_delete($nodes, $table)) {
// Solr query failed - so stop trying.
break;
}
}
}