function apachesolr_index_report in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.admin.inc \apachesolr_index_report()
- 5.2 apachesolr.admin.inc \apachesolr_index_report()
- 6.3 apachesolr.admin.inc \apachesolr_index_report()
- 6 apachesolr.admin.inc \apachesolr_index_report()
- 6.2 apachesolr.admin.inc \apachesolr_index_report()
Get the report.
Return some statistics and useful data from the Apache Solr index.
Parameters
array $environment: A single environment to report on.
Return value
array Page render array.
1 string reference to 'apachesolr_index_report'
- apachesolr_menu in ./
apachesolr.module - Implements hook_menu().
File
- ./
apachesolr.admin.inc, line 654 - Administrative pages for the Apache Solr framework.
Code
function apachesolr_index_report(array $environment = array()) {
if (empty($environment)) {
$env_id = apachesolr_default_environment();
drupal_goto('admin/reports/apachesolr/' . $env_id);
}
$environments = apachesolr_load_all_environments();
$environments_list = array();
foreach ($environments as $env) {
$var_status = array(
'!name' => $env['name'],
);
$environments_list[] = l(t('Statistics for !name', $var_status), 'admin/reports/apachesolr/' . $env['env_id']);
}
$output['environments_list'] = array(
'#theme' => 'item_list',
'#items' => $environments_list,
);
try {
$solr = apachesolr_get_solr($environment['env_id']);
$solr
->clearCache();
$data = $solr
->getLuke();
} catch (Exception $e) {
apachesolr_log_exception($environment['env_id'], $e);
drupal_set_message(nl2br(check_plain($e
->getMessage())), "warning");
return $output;
}
$messages = array();
$messages[] = array(
t('Number of documents in index'),
$data->index->numDocs,
);
$limit = variable_get('apachesolr_luke_limit', 20000);
if (isset($data->index->numDocs) && $data->index->numDocs > $limit) {
$messages[] = array(
t('Limit'),
t('You have more than @limit documents, so term frequencies are being omitted for performance reasons.', array(
'@limit' => $limit,
)),
);
$not_found = t('<em>Omitted</em>');
}
elseif (isset($data->index->numDocs)) {
$not_found = t('Not indexed');
try {
$solr = apachesolr_get_solr($environment['env_id']);
// Note: we use 2 since 1 fails on Ubuntu Hardy.
$data = $solr
->getLuke(2);
if (isset($data->index->numTerms)) {
$messages[] = array(
t('# of terms in index'),
$data->index->numTerms,
);
}
} catch (Exception $e) {
apachesolr_log_exception($environment['env_id'], $e);
$data->fields = array();
}
}
// Initializes output with information about which server's setting we are
// editing, as it is otherwise not transparent to the end user.
$fields = (array) $data->fields;
if ($fields) {
$messages[] = array(
t('# of fields in index'),
count($fields),
);
}
// Output the messages we have for this page.
$output['apachesolr_index_report'] = array(
'#theme' => 'table',
'#header' => array(
'type',
'value',
),
'#rows' => $messages,
);
if ($fields) {
// Initializes table header.
$header = array(
'name' => t('Field name'),
'type' => t('Index type'),
'docs' => t('Documents'),
'terms' => t('Distinct Terms'),
);
// Builds table rows.
$rows = array();
foreach ($fields as $name => $field) {
// TODO: try to map the name to something more meaningful.
$rows[$name] = array(
'name' => $name,
'type' => $field->type,
'docs' => isset($field->docs) ? $field->docs : $not_found,
'terms' => isset($field->distinct) ? $field->distinct : $not_found,
);
}
ksort($rows);
// Output the fields we found for this environment.
$output['field_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
}
else {
$output['field_table'] = array(
'#markup' => t('No data on indexed fields.'),
);
}
return $output;
}