function apachesolr_user_user_to_document in Apachesolr User 6
Given a node ID, return a document representing that node.
1 call to apachesolr_user_user_to_document()
File
- ./
apachesolr_user.module, line 137
Code
function apachesolr_user_user_to_document($uid, $namespace) {
include_once drupal_get_path('module', 'apachesolr') . '/apachesolr.index.inc';
include_once drupal_get_path('module', 'apachesolr') . '/SolrPhpClient/Apache/Solr/Document.php';
$user = user_load($uid, NULL, TRUE);
if (empty($user)) {
return FALSE;
}
$document = FALSE;
// Let any module exclude this node from the index.
$build_document = TRUE;
if ($build_document) {
// Build the node body.
$node->body = $user->name;
$node->title = $user->name;
$text = $node->name;
$profile = array();
foreach ($user as $key => $value) {
if (stristr($key, 'profile_')) {
// At the moment this can only be a date
if (is_array($value)) {
$value = sprintf('%s-%s-%s', $value['year'], $value['month'], $value['day']);
}
$profile[$key] = $value;
}
}
$text .= "\n\n" . implode(' ', $profile);
$document = new Apache_Solr_Document();
$document->id = apachesolr_document_id($user->uid, 'user');
$document->hash = apachesolr_site_hash();
$document->entity = 'user';
$document->nid = $user->uid;
$document->uid = $user->uid;
$document->title = $node->title;
$document->status = $user->status;
$document->body = apachesolr_clean_text($text);
$document->type = 'user';
$document->type_name = 'user';
$document->created = apachesolr_date_iso($user->created);
$document->name = $user->name;
$path = 'user/' . $user->uid;
// Picture
$document->{'ss_picture'} = $user->picute;
// Signature
$document->{'ts_signature'} = $user->signature;
$document->url = url($path, array(
'absolute' => TRUE,
));
$document->path = $path;
// Path aliases can have important information about the content.
// Add them to the index as well.
if (function_exists('drupal_get_path_alias')) {
// Add any path alias to the index, looking first for language specific
// aliases but using language neutral aliases otherwise.
$language = empty($node->language) ? '' : $node->language;
$output = drupal_get_path_alias($path, $language);
if ($output && $output != $path) {
$document->path_alias = $output;
}
}
// Profile Fields
foreach ($profile as $key => $value) {
$profile_info = false;
$profile_info = apachesolr_user_get_profile_info($key);
// At the moment we only index items that are visible to the
if ($profile_info['visibility'] > 1 && !empty($value)) {
$index_key = apachesolr_user_profile_index_key($profile_info);
// if (isset($value['value']) && strlen($value['value'])) {
// if ($cck_info['multiple']) {
// $document->setMultiValue($index_key, apachesolr_clean_text($value['value']));
// }
// else {
if ($profile_info['type'] == 'date') {
$value = strtotime($value);
$document->{$index_key} = apachesolr_date_iso($value);
}
else {
$document->{$index_key} = apachesolr_clean_text($value);
}
}
}
// Let modules add to the document.
foreach (module_implements('apachesolr_user_update_index') as $module) {
$function = $module . 'apachesolr_user_update_index';
$function($document, $node, $namespace);
}
}
return $document;
}