diff --git a/classes/ezfindresultnode.php b/classes/ezfindresultnode.php index 7f1b4f84..3ee5366f 100644 --- a/classes/ezfindresultnode.php +++ b/classes/ezfindresultnode.php @@ -18,15 +18,17 @@ public function __construct( $rows = array() ) $this->ContentObjectID = $rows['id']; } $this->LocalAttributeValueList = array(); - $this->LocalAttributeNameList = array( 'is_local_installation', - 'name', - 'global_url_alias', - 'published', - 'language_code', - 'highlight', - 'score_percent', - 'elevated' - ); + $this->LocalAttributeNameList = array( + 'is_local_installation', + 'name', + 'global_url_alias', + 'published', + 'language_code', // should not be here + 'highlight', + 'score_percent', + 'elevated', + 'doc', + ); } /*! @@ -36,45 +38,70 @@ function attribute( $attr, $noFunction = false ) { $retVal = null; - switch ( $attr ) + // SOLR specific attributes + if( in_array( $attr, $this->LocalAttributeNameList ) ) { - case 'object': + // Extra effort for language code - keeping BC + if( $attr == 'language_code' ) { if ( $this->attribute( 'is_local_installation' ) ) { - $retVal = eZContentObjectTreeNode::attribute( $attr, $noFunction ); + $eZObj = parent::attribute( 'object' ); + $retVal = $eZObj->attribute( 'current_language' ); } else { - if ( empty( $this->ResultObject ) ) - { - $this->ResultObject = new eZFindResultObject( array( 'published' => $this->attribute( 'published' ) ) ); - } - $retVal = $this->ResultObject; + $retVal = $this->CurrentLanguage; } - } break; - - case 'language_code': - { - $retVal = $this->CurrentLanguage; - } break; - - default: + } + else { - if ( in_array( $attr, $this->LocalAttributeNameList ) ) + $retVal = isset( $this->LocalAttributeValueList[ $attr ] ) ? $this->LocalAttributeValueList[$attr] : null; + // Timestamps are stored as strings for remote objects, so it must be converted. + if ( $attr == 'published' ) { - $retVal = isset( $this->LocalAttributeValueList[$attr] ) ? $this->LocalAttributeValueList[$attr] : null; - // Timestamps are stored as strings for remote objects, so it must be converted. - if ( $attr == 'published' ) - { - $retVal = strtotime( $retVal ); - } + $retVal = strtotime( $retVal ); } - else if ( $this->attribute( 'is_local_installation' ) ) + } + } + else + { + if ( $this->attribute( 'is_local_installation' ) ) + { + $retVal = eZContentObjectTreeNode::attribute( $attr, $noFunction ); + } + else + { + switch ( $attr ) { - $retVal = eZContentObjectTreeNode::attribute( $attr, $noFunction ); + case 'object': + { + if ( empty( $this->ResultObject ) ) + { + $objectRow = array( + 'doc' => &$this->LocalAttributeValueList[ 'doc' ] + ); + $this->ResultObject = new eZFindResultObject( $objectRow ); + } + + $retVal = $this->ResultObject; + } break; + + case 'class_identifier': + case 'contentclass_id': + case 'state_id_array': + { + /** @var eZFindResultObject $resultObject */ + $resultObject = $this->attribute( 'object' ); + $retVal = $resultObject->attribute( $attr ); + } break; + + case 'url_alias': + { + $retVal = $this->LocalAttributeValueList[ 'doc' ][ 'meta_main_url_alias_ms' ]; + } break; } - } break; + } } return $retVal; diff --git a/classes/ezfindresultobject.php b/classes/ezfindresultobject.php index 7191f8c3..79abc33c 100644 --- a/classes/ezfindresultobject.php +++ b/classes/ezfindresultobject.php @@ -13,7 +13,7 @@ class eZFindResultObject extends eZContentObject function __construct( $rows = array() ) { $this->LocalAttributeValueList = array(); - $this->LocalAttributeNameList = array( 'published' ); + $this->LocalAttributeNameList = array( 'doc' ); foreach ( $rows as $name => $value ) { @@ -26,8 +26,35 @@ function __construct( $rows = array() ) */ function attribute( $attr, $noFunction = false ) { - return isset( $this->LocalAttributeValueList[$attr] ) ? - $this->LocalAttributeValueList[$attr] : null; + $returnVal = null; + + if( isset( $this->LocalAttributeValueList[ $attr ] ) ) + { + $returnVal = $this->LocalAttributeValueList[ $attr ]; + } + else + { + switch( $attr ) + { + case 'published': + { + $returnVal = strtotime( $this->LocalAttributeValueList[ 'doc' ][ eZSolr::getMetaFieldName( 'published' ) ] ); + } break; + + case 'state_id_array': + { + $returnVal = $this->LocalAttributeValueList[ 'doc' ][ eZSolr::getMetaFieldName( 'object_states' ) ]; + } break; + + case 'contentclass_id': + case 'class_identifier': + { + $returnVal = $this->LocalAttributeValueList[ 'doc' ][ eZSolr::getMetaFieldName( $attr ) ]; + } break; + } + } + + return $returnVal; } /*! diff --git a/search/plugins/ezsolr/ezsolr.php b/search/plugins/ezsolr/ezsolr.php index ae7cef2f..c9d67a75 100644 --- a/search/plugins/ezsolr/ezsolr.php +++ b/search/plugins/ezsolr/ezsolr.php @@ -1767,6 +1767,7 @@ protected function buildResultObjects( $resultArray, &$searchCount, $asObjects = } $resultTree->setAttribute( 'name', $doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'name' )] ); + $resultTree->setAttribute( 'doc', $doc ); $resultTree->setAttribute( 'published', $doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'published' )] ); $resultTree->setAttribute( 'global_url_alias', $globalURL ); $resultTree->setAttribute( 'highlight', isset( $highLights[$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'guid' )]] ) ?