Hi I upgraded from the version 1 to version 3 of the apache solr module under drupal 6. It seems version 1 used the human readable name for showing the content type in the search results. Now that I have switched to the newer version my search results show the machine name. Is there anyway to change it back to show the human readable name? If not consider this a feature request.

Comments

deverman’s picture

StatusFileSize
new115.19 KB

Just attaching a screen shot to hopefully make it clearer what I mean.

nick_vh’s picture

StatusFileSize
new1.06 KB

This seems more a facetapi implementation bug.

So let's analyse this. In the apachesolr_search_process_response we do the following snippet and take the entity_type directly from the document.

      $result = array(
        // link is a required field, so handle it centrally.
        'link' => $path,
        // template_preprocess_search_result() runs check_plain() on the title
        // again.  Decode to correct the display.
        'title' => htmlspecialchars_decode($doc->label, ENT_QUOTES),
        // These values are not required by the search module but are provided
        // to give entity callbacks and themers more flexibility.
        'score' => $doc->score,
        'snippets' => $snippets,
        'snippet' => $snippet,
        'fields' => $fields,
        'entity_type' => $doc->entity_type,
        'bundle' => $bundle,
      );

And then in D6 we have the following function to process these vars :

/**
 * Process variables for search-result.tpl.php.
 *
 * The $variables array contains the following arguments:
 * - $result
 * - $type
 *
 * @see search-result.tpl.php
 */
function template_preprocess_search_result(&$variables) {
  $result = $variables['result'];
  $variables['url'] = check_url($result['link']);
  $variables['title'] = check_plain($result['title']);

  $info = array();
  if (!empty($result['type'])) {
    $info['type'] = check_plain($result['type']);
  }
  if (!empty($result['user'])) {
    $info['user'] = $result['user'];
  }
  if (!empty($result['date'])) {
    $info['date'] = format_date($result['date'], 'small');
  }
  if (isset($result['extra']) && is_array($result['extra'])) {
    $info = array_merge($info, $result['extra']);
  }
  // Check for existence. User search does not include snippets.
  $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
  // Provide separated and grouped meta information..
  $variables['info_split'] = $info;
  $variables['info'] = implode(' - ', $info);
  // Provide alternate search result template.
  $variables['template_files'][] = 'search-result-'. $variables['type'];
}

The real responsible for this function is this. So we have two options now. Or you, as a site builder override this theme function and you load the respective type properly. Or we need to fix what we give to the theme function as the theme function itself cannot be changed (belongs to Drupal core)

if (!empty($result['type'])) {
    $info['type'] = check_plain($result['type']);
  }

Let's look at what 6.x-1.x did :

'type' => apachesolr_search_get_type($doc->type),

Aha! This looks like what we need.

The parsing code for this type happens in the result callback :

/**
 * Callback function for node search results.
 *
 * @param stdClass $doc
 *   The result document from Apache Solr.
 * @param array $result
 *   The result array for this record to which to add.
 */
function apachesolr_search_node_result($doc, &$result, &$extra) {
  $doc->uid = $doc->is_uid;
  $result += array(
    'type' => $doc->bundle,
    'user' => theme('username', $doc),
    'date' => isset($doc->changed) ? $doc->changed : 0,
    'node' => $doc,
    'uid' => $doc->is_uid,
  );

  if (isset($doc->is_comment_count)) {
    $extra['comments'] = format_plural($doc->is_comment_count, '1 comment', '@count comments');
  }
}

So let's add the same code of 6.x-1.x back and tada, we have a good solution.

nick_vh’s picture

Version: 6.x-3.0-rc1 » 6.x-3.x-dev
Status: Active » Needs review
nick_vh’s picture

Status: Needs review » Fixed

Committed and marked as fixed. Thanks for the report

nick_vh’s picture

Status: Fixed » Closed (fixed)

Closing to clean the issue queue a bit