I had great difficulty getting an indexing callback for a cck field to work.

My apachesolr_cck_fields_alter implementation and indexing callback looked like this:

/**
* Implementation of hook_apachesolr_cck_fields_alter
*/
function custom_search_apachesolr_cck_fields_alter(&$mappings) {
  $mappings['per-field']['field_location'] = array(
    'indexing callback' => custom_search_index_location',
    'index_type' => 'string',
  );
  return $mappings;
}

function custom_search_index_location($node, $key) {
  $fields = array();
  foreach ($node->$key as $field) {
    $fields[] = array('value' => check_plain($field['city'] . ', ' . $field['province']));
  }
  return $fields;
}

Debugging lead me to several problems in apachesolr_node_to_document():

  • It is looking for the indexing callback in $cck_info['indexing callback']. This does not exist. It does exist as $cck_info['indexing_callback'].
  • Attempting to index a field with a non-existing indexing callback still indexed the field with the $index_value for the previous field because $index_value was not being reset on each iteration.
  • Adding a custom indexing callback for a field type other than text, nodereference, or userreference fields was impossible.
  • Adding a custom indexing callback for a nodereference or userreference field forces the indexing callback to return an array with the key 'nid' or 'uid' set as the value. Using just 'value' for any field type would cause less confusion when implementing indexing callbacks.

The attached patch attempts to fix these problems.

CommentFileSizeAuthor
apachesolr_cck_fields.patch1.92 KBjtsnow

Comments

robertdouglass’s picture

I'm working on a larger patch for cck dates that shuffles things around quite a bit and also fixes this particular problem. Thanks for reporting, and stay tuned.

drewish’s picture

Status: Active » Needs review

fixing the status.

is #558160: date facet for cck field related to this?

robertdouglass’s picture

Status: Needs review » Needs work

Is this still an issue with latest 6.x-2.x?

mcarbone’s picture

I'm still having the problem of $cck_info['indexing_callback'] not having a value for a text field with the 'Select list' widget, which is leading to that field not being indexed. Not sure if it's related. More info here: http://drupal.org/node/558160#comment-2734454

robertdouglass’s picture

This should now be fixed for 6.2 in the .dev branch.

robertdouglass’s picture

Status: Needs work » Fixed

Marking as fixed unless someone has a contrary experience.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.