Skip to content

Instantly share code, notes, and snippets.

@drupler
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drupler/125bd3346f9926bebcf4 to your computer and use it in GitHub Desktop.
Save drupler/125bd3346f9926bebcf4 to your computer and use it in GitHub Desktop.
$entity_type = 'node';
$entity_id = mynodeid;
$table = apachesolr_get_indexer_table($entity_type);
$env_id = apachesolr_default_environment();
$query = db_select($table, 'aie')
->fields('aie')
->condition('aie.entity_id', $entity_id, '=');
if ($table == 'apachesolr_index_entities') {
// Other, entity-specific tables don't need this condition.
$query->condition('aie.entity_type', $entity_type);
}
$records = $query->execute();
foreach ($records as $row) {
// $row_documents = _apachesolr_index_entities_document($row, $entity_type, $env_id);
print_r($row_documents);
}
function _apachesolr_index_entities_document($row, $entity_type, $env_id) {
$documents = array();
if (!empty($row->status)) {
// Let any module exclude this entity from the index.
$build_document = TRUE;
foreach (module_implements('apachesolr_exclude') as $module) {
$exclude = module_invoke($module, 'apachesolr_exclude', $row->entity_id, $entity_type, $row, $env_id);
// If the hook returns TRUE we should exclude the entity
if (!empty($exclude)) {
$build_document = FALSE;
}
}
foreach (module_implements('apachesolr_' . $entity_type . '_exclude') as $module) {
$exclude = module_invoke($module, 'apachesolr_' . $entity_type . '_exclude', $row->entity_id, $row, $env_id);
// If the hook returns TRUE we should exclude the entity
if (!empty($exclude)) {
$build_document = FALSE;
}
}
if ($build_document) {
$documents = array_merge($documents, apachesolr_index_entity_to_documents($row, $env_id));
}
}
else {
// Delete the entity from our index if the status callback returned 0
apachesolr_remove_entity($env_id, $row->entity_type, $row->entity_id);
}
// Clear entity cache for this specific entity
entity_get_controller($row->entity_type)->resetCache(array($row->entity_id));
return $documents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment