Tuesday 15 June 2010 5:20:10 am
This method is invoked to extract data from eZ Publish, and prepare it prior to indexing in Solr. This method is the place to add additional fields like 'year' et 'yearmonth'. Once these new fields (subattributes) are indexed, we will leverage them by facetting or filtering on them, using the following, classical syntax:
public function getData() { $contentClassAttribute = $this->ContentObjectAttribute->attribute( 'contentclass_attribute' ); switch ( $contentClassAttribute->attribute( 'data_type_string' ) ) { case 'ezdate' : { $returnArray = array(); // Get timestamp attribute value $value = $this->ContentObjectAttribute->metaData(); // Generate the main filedName attr_XXX_dt $fieldName = parent::generateAttributeFieldName( $contentClassAttribute, self::DEFAULT_ATTRIBUTE_TYPE ); $returnArray[$fieldName] = parent::convertTimestampToDate( $value ); // Generate the yearmonth subattribute filedName subattr_year_dt $fieldName = parent::generateSubattributeFieldName( $contentClassAttribute, 'year', self::DEFAULT_SUBATTRIBUTE_TYPE ); $year = date("Y", $value); // Get Year value : 2010 $returnArray[$fieldName] = parent::convertTimestampToDate( strtotime($year.'-01-01') ); // Generate the yearmonth subattribute filedName subattr_yearmonth_dt $fieldName = parent::generateSubattributeFieldName( $contentClassAttribute, 'yearmonth', self::DEFAULT_SUBATTRIBUTE_TYPE ); $month = date("n", $value); // Get Month value : 3 $returnArray[$fieldName] = parent::convertTimestampToDate( strtotime($year.'-'.$month.'-01') ); return $returnArray; } break; default: {} break; } } }
Note:
$returnArray contains an associative array looking like this ( using var_dump ) :
array(3) { ["attr_date_dt"]=> string(24) "2008-12-28T00:00:00.000Z" ["subattr_date-year_dt"]=> string(24) "2008-01-01T00:00:00.000Z" ["subattr_date-yearmonth_dt"]=> string(24) "2008-12-01T00:00:00.000Z" }
Note :
Solr uses the ISO 8601 date format, of the form : '2010-04-30T00:00:00Z'. The parent class ( ezfSolrDocumentFieldBase ) exposes the convertTimestampToDate() methodm used to convert a timestamp to an ISO 8601 formatted date.