function apachesolr_date_default_indexing_callback in Apache Solr Search 8
Same name and namespace in other branches
- 6.3 apachesolr.index.inc \apachesolr_date_default_indexing_callback()
- 7 apachesolr.index.inc \apachesolr_date_default_indexing_callback()
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 string reference to 'apachesolr_date_default_indexing_callback'
- date_apachesolr_field_mappings in ./
apachesolr.module - Implements hook_apachesolr_field_mappings() on behalf of date module.
File
- ./
apachesolr.index.inc, line 1152 - Functions related to Apache Solr indexing operations.
Code
function apachesolr_date_default_indexing_callback($entity, $field_name, $index_key, array $field_info) {
$fields = array();
if (!empty($entity->{$field_name})) {
$field = $entity->{$field_name};
list($lang, $values) = each($field);
// 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;
}