function apachesolr_index_user_solr_document in Apachesolr User 7
Builds the user-specific information for a Solr document.
Parameters
ApacheSolrDocument $document: The Solr document we are building up.
stdClass $entity: The entity we are indexing.
string $entity_type: The type of entity we're dealing with.
1 string reference to 'apachesolr_index_user_solr_document'
- apachesolr_user_apachesolr_entity_info_alter in ./
apachesolr_user.module - @file Indexer for the user entities for the Apachesolr module.
File
- ./
apachesolr_user.module, line 53 - Indexer for the user entities for the Apachesolr module.
Code
function apachesolr_index_user_solr_document(ApacheSolrDocument $document, $account, $entity_type) {
$document->uid = $account->uid;
// Title is a required field.
$document->label = apachesolr_clean_text(format_username($account));
$document->mail = $account->mail;
$document->signature = $account->signature;
// Note the conspicuous lack of password hash. :-)
// get all props into an array
$fields = get_object_vars($account);
foreach ($fields as $key => $value) {
if (preg_match('/field_.+$/', $key) === 0) {
unset($fields[$key]);
}
}
// create doc fields
foreach ($fields as $key => $value) {
$field_values = field_view_field('user', $account, $key, $value, array(
'',
));
$field_index = array();
foreach ($field_values as $delta => $field_value) {
if (is_numeric($delta) && isset($field_value['#markup']) && strlen($field_value['#markup']) > 0) {
$field_index[] = apachesolr_clean_text($field_value['#markup']);
}
}
if (sizeof($field_index) > 1) {
$slr_key = str_replace('field_', 'tm_', $key);
$document->{$slr_key} = $field_index;
$smlr_key = str_replace('field_', 'sm_', $key);
$document->{$smlr_key} = $field_index;
}
elseif (sizeof($field_index) == 1) {
$slr_key = str_replace('field_', 'ts_', $key);
$document->{$slr_key} = $field_index[0];
$sslr_key = str_replace('field_', 'ss_', $key);
$document->{$sslr_key} = $field_index[0];
}
}
// Build the user body.
$build = user_view($account, 'search_index');
// Why do we need this?
unset($build['#theme']);
$text = drupal_render($build);
$document->content = apachesolr_clean_text($text);
$document->bs_status = $account->status;
$document->created = apachesolr_date_iso($account->created);
$document->access = apachesolr_date_iso($account->access);
$document->im_rids = array_keys($account->roles);
// Generic usecase for future reference. Callbacks can
// allow you to send back multiple documents
drupal_alter('apachesolr_index_user_solr_document', $document);
$documents = array();
$documents[] = $document;
return $documents;
}