You are here

function apachesolr_index_report in Apache Solr Search 6

Same name and namespace in other branches
  1. 8 apachesolr.admin.inc \apachesolr_index_report()
  2. 5.2 apachesolr.admin.inc \apachesolr_index_report()
  3. 6.3 apachesolr.admin.inc \apachesolr_index_report()
  4. 6.2 apachesolr.admin.inc \apachesolr_index_report()
  5. 7 apachesolr.admin.inc \apachesolr_index_report()
1 string reference to 'apachesolr_index_report'
apachesolr_menu in ./apachesolr.module
Implementation of hook_menu().

File

./apachesolr.admin.inc, line 181
Administrative pages for the Apache Solr framework.

Code

function apachesolr_index_report() {
  try {
    $solr = apachesolr_get_solr();

    // TODO: possibly clear this every page view if we are running multi-site.
    if (apachesolr_index_updated()) {
      $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");
    $data->fields = array();
  }
  $output = '<p>' . t('Number of documents in index: @num !pending', array(
    '@num' => $data->index->numDocs,
    '!pending' => '',
  )) . "</p>\n";
  $limit = variable_get('apachesolr_luke_limit', 20000);
  if (isset($data->index->numDocs) && $data->index->numDocs > $limit) {
    $output .= '<p>' . t('You have more than @limit documents, so term frequencies are being omitted for performance reasons.', array(
      '@limit' => $limit,
    )) . "</p>\n";
    $not_found = t('<em>Omitted</em>');
  }
  elseif (isset($data->index->numDocs)) {
    $not_found = t('Not indexed');
    try {
      $solr = apachesolr_get_solr();

      // Note: we use 2 since 1 fails on Ubuntu Hardy.
      $data = $solr
        ->getLuke(2);
      $output .= '<p>' . t('Number of terms in index: @num', array(
        '@num' => $data->index->numTerms,
      )) . "</p>\n";
    } catch (Exception $e) {
      watchdog('Apache Solr', nl2br(check_plain($e
        ->getMessage())), NULL, WATCHDOG_ERROR);
      $data->fields = array();
    }
  }
  $fields = (array) $data->fields;
  if ($fields) {
    $output .= '<p>' . t('Number of fields in index: @num', array(
      '@num' => count($fields),
    )) . "</p>\n";
    $rows = array();
    foreach ($fields as $name => $field) {

      // TODO: try to map the name to something more meaningful.
      $rows[$name] = array(
        $name,
        $field->type,
        isset($field->distinct) ? $field->distinct : $not_found,
      );
    }
    ksort($rows);

    // Display the table of Field names, Index Types, and term counts.
    $output .= theme('table', array(
      t('Field name'),
      t('Index type'),
      t('Distinct terms'),
    ), $rows);
  }
  else {
    $output .= '<p>' . t('No data on indexed fields.') . "</p>\n";
  }
  return $output;
}