function apachesolr_process_response in Apache Solr Search 6
Same name and namespace in other branches
- 5.2 apachesolr_search.module \apachesolr_process_response()
1 call to apachesolr_process_response()
- apachesolr_search_execute in ./
apachesolr_search.module - Execute a search results based on keyword, filter, and sort strings.
File
- ./
apachesolr_search.module, line 396 - Provides a content search implementation for node content for use with the Apache Solr search application.
Code
function apachesolr_process_response($response, $query, $params) {
$results = array();
// We default to getting snippets from the body.
$hl_fl = isset($params['hl.fl']) ? $params['hl.fl'] : 'body';
$total = $response->response->numFound;
apachesolr_pager_init($total, $params['rows']);
if ($total > 0) {
foreach ($response->response->docs as $doc) {
$extra = array();
// Find the nicest available snippet.
if (isset($response->highlighting->{$doc->id}->{$hl_fl})) {
$snippet = theme('apachesolr_search_snippets', $doc, $response->highlighting->{$doc->id}->{$hl_fl});
}
elseif (isset($doc->teaser)) {
$snippet = theme('apachesolr_search_snippets', $doc, array(
truncate_utf8($doc->teaser, 256, TRUE),
));
}
else {
$snippet = '';
}
if (!isset($doc->body)) {
$doc->body = $snippet;
}
$doc->created = strtotime($doc->created);
$doc->changed = strtotime($doc->changed);
// Allow modules to alter each document.
drupal_alter('apachesolr_search_result', $doc);
// Copy code from comment_nodeapi().
$extra[] = format_plural($doc->comment_count, '1 comment', '@count comments');
// Copy code from upload_nodeapi()
if (isset($doc->is_upload_count)) {
$extra[] = format_plural($doc->is_upload_count, '1 attachment', '@count attachments');
}
$fields = (array) $doc;
$results[] = array(
'link' => url($doc->path, array(
'absolute' => TRUE,
)),
'type' => apachesolr_search_get_type($doc->type),
// template_preprocess_search_result() runs check_plain() on the title
// again. Decode to correct the display.
'title' => htmlspecialchars_decode($doc->title, ENT_QUOTES),
'user' => theme('username', $doc),
'date' => $doc->changed,
'node' => $doc,
'extra' => $extra,
'score' => $doc->score,
'snippet' => $snippet,
'fields' => $fields,
);
}
// Hook to allow modifications of the retrieved results
foreach (module_implements('apachesolr_process_results') as $module) {
$function = $module . '_apachesolr_process_results';
$function($results);
}
}
return $results;
}