I'm creating an application that indexes datetime and number_integer fields, and using hook_apachesolr_cck_fields_alter() I'm able to add mappings for these cck types. However, when it comes time for apachesolr to index these fields, here is the loop they get sent through to set $index_value:
// Don't index NULLs or empty strings
// We can use 'value' rather than 'safe' since we strip tags and later check_plain().
// Furthermore, what is being indexed is the KEY for the CCK value. It will need
// a trip through content_format() later to display the value.
switch ($cck_info['field_type']) {
case 'text':
$index_value = (isset($value['value']) && strlen($value['value'])) ? $value['value'] : FALSE;
break;
case 'nodereference':
$index_value = (isset($value['nid']) && strlen($value['nid'])) ? $value['nid'] : FALSE;
break;
case 'userreference':
$index_value = (isset($value['uid']) && strlen($value['uid'])) ? $value['uid'] : FALSE;
break;
}
if ($index_value) {
if ($cck_info['multiple']) {
$document->setMultiValue($index_key, apachesolr_clean_text($index_value));
}
else {
$document->$index_key = apachesolr_clean_text($index_value);
}
}
Because the field type is none of those in the switch, the fields don't get indexed. Even worse, since $index_value is never properly initialized in the loop, the fields are indexed with the value from the preceding field.
I can hack this to hard-code datetime and number_integer in like this:
switch ($cck_info['field_type']) {
case 'datetime':
case 'number_integer':
case 'text':
$index_value = (isset($value['value']) && strlen($value['value'])) ? $value['value'] : FALSE;
break;
but that is not a nice or flexible solution. Would adding an additional callback, named perhaps indexing value callback to cck mappings be the way to go here?
Something like this:
'
<?php
case 'userreference':
$index_value = (isset($value['uid']) && strlen($value['uid'])) ? $value['uid'] : FALSE;
break;
default:
// Check for an index value callback.
$function = $cck_info['indexing value callback'];
if ($function && function_exists($function)) {
$index_value = $function($value);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | cck-index.patch | 2.97 KB | robertdouglass |
Comments
Comment #1
robertdouglass commentedTrue. Very true. Patch fixes that by making the default handling index $field['value'].
Comment #2
robertdouglass commented#604566 by robertDouglass | jhedstrom: Fixed index_value() never set for CCK fields that aren't of type text, node or user reference.
This also fixes a PHP notice that occurs when trying to add CCK facets.