function apachesolr_multilingual_date_default_indexing_callback_implementation in Apache Solr Multilingual 7
This function is used during indexing to normalize the DATE and DATETIME fields into the appropriate format for Apache Solr.
Parameters
object $entity:
string $field_name:
string $index_key:
array $field_info:
Return value
array $fields
1 call to apachesolr_multilingual_date_default_indexing_callback_implementation()
- apachesolr_multilingual_date_default_indexing_callback in ./
apachesolr_multilingual.module - This function is used during indexing to normalize the DATE and DATETIME fields into the appropriate format for Apache Solr.
File
- ./
apachesolr_multilingual.index.inc, line 81
Code
function apachesolr_multilingual_date_default_indexing_callback_implementation($entity, $field_name, $index_key, array $field_info) {
$fields = array();
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();
}
}
// Construct a Solr-ready date string in UTC time zone based on the field's date string and time zone.
$tz = new DateTimeZone(isset($field['timezone']) ? $field['timezone'] : 'UTC');
// $fields may end up having two values; one for the start date
// and one for the end date.
foreach ($values as $value) {
if ($date = date_create($value['value'], $tz)) {
$index_value = apachesolr_date_iso($date
->format('U'));
$fields[] = array(
'key' => $index_key,
'value' => $index_value,
);
}
if (isset($value['value2'])) {
if ($date = date_create($value['value2'], $tz)) {
$index_value = apachesolr_date_iso($date
->format('U'));
$fields[] = array(
// The value2 element is the end date. Therefore it gets indexed
// into its own Solr field.
'key' => $index_key . '_end',
'value' => $index_value,
);
}
}
}
}
return $fields;
}