You are here

function apachesolr_multilingual_fields_default_indexing_callback_implementation in Apache Solr Multilingual 7

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

1 call to apachesolr_multilingual_fields_default_indexing_callback_implementation()
apachesolr_multilingual_fields_default_indexing_callback in ./apachesolr_multilingual.module
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

File

./apachesolr_multilingual.index.inc, line 14

Code

function apachesolr_multilingual_fields_default_indexing_callback_implementation($entity, $field_name, $index_key, array $field_info) {
  $fields = array();
  $numeric = TRUE;
  if (!empty($entity->{$field_name})) {
    $field = $entity->{$field_name};
    $values = array();
    if (array_key_exists($entity->language, $field) && is_array($field[$entity->language])) {
      $values = $field[$entity->language];
    }
    else {
      list($lang, $values) = each($field);
      if (!is_array($values)) {
        $values = array();
      }
    }
    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;
}