function apachesolr_user_index_users in Apachesolr User 6
1 call to apachesolr_user_index_users()
- apachesolr_user_update_index in ./
apachesolr_user.module - This module will index users and there profile information in Solr. As this is a D6 module we are treating them like nodes
File
- ./
apachesolr_user.module, line 38
Code
function apachesolr_user_index_users($rows, $namespace = '', $callback = 'apachesolr_user_add_user_document') {
if (!$rows) {
// Nothing to do.
return FALSE;
}
try {
// Get the $solr object
$solr = apachesolr_get_solr();
// If there is no server available, don't continue.
if (!$solr
->ping(variable_get('apachesolr_ping_timeout', 4))) {
throw new Exception(t('No Solr instance available during indexing.'));
}
} catch (Exception $e) {
watchdog('Apache Solr', nl2br(check_plain($e
->getMessage())), NULL, WATCHDOG_ERROR);
return FALSE;
}
$documents = array();
$old_position = apachesolr_get_last_index($namespace);
$position = $old_position;
foreach ($rows as $row) {
try {
$callback($documents, $row->nid, $namespace);
// Variables to track the last item changed.
$position['last_change'] = $row->changed;
$position['last_nid'] = $row->nid;
} catch (Exception $e) {
// Something bad happened - don't continue.
watchdog('Apache Solr', 'Error constructing documents to index: <br /> !message', array(
'!message' => nl2br(strip_tags($e
->getMessage())),
), WATCHDOG_ERROR);
break;
}
}
if (count($documents)) {
try {
watchdog('Apache Solr', 'Adding @count documents.', array(
'@count' => count($documents),
));
// Chunk the adds by 20s
$docs_chunk = array_chunk($documents, 20);
foreach ($docs_chunk as $docs) {
$solr
->addDocuments($docs);
}
// Set the timestamp to indicate an index update.
apachesolr_index_updated(time());
} catch (Exception $e) {
$nids = array();
if (!empty($docs)) {
foreach ($docs as $doc) {
$nids[] = $doc->nid;
}
}
watchdog('Apache Solr', 'Indexing failed on one of the following nodes: @nids <br /> !message', array(
'@nids' => implode(', ', $nids),
'!message' => nl2br(strip_tags($e
->getMessage())),
), WATCHDOG_ERROR);
return FALSE;
}
}
// Save the new position in case it changed.
if ($namespace && $position != $old_position) {
$stored = variable_get('apachesolr_index_last', array());
$stored[$namespace] = $position;
variable_set('apachesolr_index_last', $stored);
}
return $position;
}