You are here

function apachesolr_index_report in Apache Solr Search 8

Same name and namespace in other branches
  1. 5.2 apachesolr.admin.inc \apachesolr_index_report()
  2. 6.3 apachesolr.admin.inc \apachesolr_index_report()
  3. 6 apachesolr.admin.inc \apachesolr_index_report()
  4. 6.2 apachesolr.admin.inc \apachesolr_index_report()
  5. 7 apachesolr.admin.inc \apachesolr_index_report()

Get the report, eg.: some statistics and useful data from the Apache Solr index

Parameters

array $environment:

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 641
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) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
    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) {
      watchdog('Apache Solr', nl2br(check_plain($e
        ->getMessage())), NULL, WATCHDOG_ERROR);
      $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'),
      '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,
        '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;
}