function apachesolr_node_type in Apache Solr Search 6.3
Same name and namespace in other branches
- 5.2 apachesolr.module \apachesolr_node_type()
- 6 apachesolr.module \apachesolr_node_type()
- 6.2 apachesolr.module \apachesolr_node_type()
Implements hook_node_type().
Mark nodes as needing re-indexing if a node type name changes.
Performance issue with Mysql To know why PDO in drupal does not support UPDATE and JOIN at once.
See also
http://api.drupal.org/api/drupal/includes--database--database.inc/functi...
File
- ./
apachesolr.module, line 729 - Integration with the Apache Solr search application.
Code
function apachesolr_node_type($op, $info) {
module_load_include('inc', 'apachesolr', 'apachesolr.index');
$env_id = apachesolr_default_environment();
if ($op == 'delete') {
$env_id = apachesolr_default_environment();
$existing_bundles = apachesolr_get_index_bundles($env_id, 'node');
$new_bundles = $existing_bundles;
$index = array_search($info->type, $existing_bundles);
if ($index !== FALSE) {
unset($new_bundles[$index]);
$new_bundles = array_values($new_bundles);
apachesolr_index_set_bundles($env_id, 'node', $new_bundles);
}
apachesolr_index_delete_bundles($env_id, 'node', array(
$info->type,
));
$callback = apachesolr_entity_get_callback('node', 'bundles changed callback');
if (!empty($callback)) {
call_user_func($callback, $env_id, $existing_bundles, $new_bundles);
}
}
elseif ($op == 'insert') {
// Get all our environments
$envs = apachesolr_load_all_environments();
$bundles = array();
foreach ($envs as $env) {
if (isset($env['index_bundles']['node'])) {
$bundles = $env['index_bundles']['node'];
}
// Is the bundle already marked?
if (!in_array($info->type, $bundles)) {
$bundles[] = $info->type;
// Set the new bundle as indexable for all environments
apachesolr_index_set_bundles($env['env_id'], 'node', $bundles);
}
}
}
elseif (!empty($info->old_type) && $info->old_type != $info->type) {
// We cannot be sure we are going before or after node module.
$table = apachesolr_get_indexer_table('node');
$query = "UPDATE {{$table}} asn\n INNER JOIN {node} n ON asn.entity_id = n.nid SET asn.changed = '%s'\n WHERE (n.type = '%s' OR n.type = '%s')";
db_query($query, array(
APACHESOLR_REQUEST_TIME,
$info->type,
$info->old_type,
));
db_query("UPDATE {apachesolr_index_bundles} SET bundle = '%s' WHERE bundle = '%s' AND entity_type = '%s'", array(
$info->type,
$info->old_type,
'node',
));
}
apachesolr_environments_clear_cache();
}