function apachesolr_date_date_field_indexing_callback in Apache Solr Search 6.2
This function is used during indexing to normalize the DATE and DATETIME fields into the appropriate format for Apache Solr.
1 string reference to 'apachesolr_date_date_field_indexing_callback'
- apachesolr_date_apachesolr_cck_fields_alter in contrib/
apachesolr_date/ apachesolr_date.module - Implementation of hook_apachesolr_cck_fields_alter(). This function adds the CCK date fields' definitions to let them be recognized as facets.
File
- contrib/
apachesolr_date/ apachesolr_date.module, line 161 - Integration with the Apache Solr search application. Provides faceting for CCK Date fields.
Code
function apachesolr_date_date_field_indexing_callback($node, $field_name, $cck_info) {
$fields = array();
if (isset($node->{$field_name})) {
$index_key = apachesolr_index_key($cck_info);
foreach ($node->{$field_name} as $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.
if (isset($field['value'])) {
if ($date = date_create($field['value'], $tz)) {
$index_value = apachesolr_date_iso($date
->format('U'));
$fields[] = array(
'key' => $index_key,
'value' => $index_value,
);
}
}
if (isset($field['value2'])) {
if ($date = date_create($field['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;
}