When we are exposing CCK fields as facets the value of the field is displayed in the facets block. For example, on a CCK Text field that uses a select widget with allowed values like:

0|Yellow
1|Red
2|Green
3|Orange

the values 0, 1, 2, 3 will be used as $facet_text instead displaying "Yellow", "Red", "Green", "Orange".

The attached patch let modules alter the CCK facet text by adding a callback the apachesolr_search_get_cck_text() and implementing a new hook:

/**
 * Implementation of hook_apachesolr_search_get_cck_text_alter()
 *
 * @param $facet_text
 *   The initial value is the $facet value. The hook implementation shoul alter this variable.
 *
 * @param $facet
 *   The facet value.
 *
 * @param $field
 *   An array containing the CCK field informations taken from _content_type_info().
 *
 * @param
 *   An array containing additional parameters.
 */
function hook_apachesolr_search_get_cck_text_alter(&$facet_text, $facet, $field, $options) {
  if ($field['type'] == 'text') {
    $allowed_values = text_allowed_values($field);
    if (isset($allowed_values[$facet])) {
      $facet_text = $allowed_values[$facet];
    }
  }
  elseif ($field['type'] == 'nodereference') {
    if ($title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $facet))) {
      $facet_text = $title;
    }
  }
}

Comments

robertdouglass’s picture

Status: Needs review » Closed (duplicate)

I think you want to check out these issues with patches that have gone into the DRUPAL-6--2 branch:

#551582: Show value instead of key in CCK facets by robertDouglass make CCK breadcrumbs, facets, and current search show the value, not the key.
#551278: CCK mappings don't respect shared fields by robertDouglass CCK mappings don't respect shared fields

I'll mark them as "to be backported" instead of "fixed", and perhaps you could help roll the 6.2 patches for 6.1 (and 5.2)?

aflijja’s picture

Status: Closed (duplicate) » Needs review

To claudiu.cristea
thanks you for your code. it help me a lot.

To the community
since the v2 is no more. il would help if it get in the v1.

Thanks again.

pwolanin’s picture

Status: Needs review » Closed (won't fix)

no new features are being added in 6.x-1.x