function apachesolr_fields_default_indexing_callback in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.index.inc \apachesolr_fields_default_indexing_callback()
- 6.3 apachesolr.index.inc \apachesolr_fields_default_indexing_callback()
Callback that converts list module field into an array For every multivalued value we also add a single value to be able to use the stats
Parameters
object $entity:
string $field_name:
string $index_key:
array $field_info:
Return value
array $fields
3 string references to 'apachesolr_fields_default_indexing_callback'
- field_apachesolr_field_mappings in ./
apachesolr.module - Implements hook_apachesolr_field_mappings().
- hook_apachesolr_field_mappings in ./
apachesolr.api.php - Add index mappings for Field API types. The default mappings array handles just list fields and taxonomy term reference fields, such as:
- hook_apachesolr_field_mappings_alter in ./
apachesolr.api.php - Alter hook for apachesolr_field_mappings().
File
- ./
apachesolr.index.inc, line 1185 - Functions related to Apache Solr indexing operations.
Code
function apachesolr_fields_default_indexing_callback($entity, $field_name, $index_key, array $field_info) {
$fields = array();
$numeric = TRUE;
if (!empty($entity->{$field_name})) {
$field = $entity->{$field_name};
$values = current($field);
switch ($field_info['index_type']) {
case 'integer':
case 'half-int':
case 'sint':
case 'tint':
case 'thalf-int':
case 'boolean':
$function = 'intval';
break;
case 'float':
case 'double':
case 'sfloat':
case 'sdouble':
case 'tfloat':
case 'tdouble':
$function = 'apachesolr_floatval';
break;
default:
$numeric = FALSE;
$function = 'apachesolr_clean_text';
}
for ($i = 0; $i < count($values); $i++) {
$fields[] = array(
'key' => $index_key,
'value' => $function($values[$i]['value']),
);
}
// Also store the first value of the field in a singular index for multi value fields
if ($field_info['multiple'] && $numeric && !empty($values[0])) {
$singular_field_info = $field_info;
$singular_field_info['multiple'] = FALSE;
$single_key = apachesolr_index_key($singular_field_info);
$fields[] = array(
'key' => $single_key,
'value' => $function($values[0]['value']),
);
}
}
return $fields;
}