Skip to content

Commit

Permalink
Adding the SOLR doc to result objects - support more attributes for n…
Browse files Browse the repository at this point in the history
…on-local SOLR result objects (#13)

* Adding the SOLR doc to result objects - support more attributes for non-local SOLR result objects

* Missing code that sets the doc added
  • Loading branch information
pkamps authored Jun 12, 2019
1 parent 2d732c8 commit 2b2d8c2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 38 deletions.
97 changes: 62 additions & 35 deletions classes/ezfindresultnode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}

/*!
Expand All @@ -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;
Expand Down
33 changes: 30 additions & 3 deletions classes/ezfindresultobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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;
}

/*!
Expand Down
1 change: 1 addition & 0 deletions search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )]] ) ?
Expand Down

0 comments on commit 2b2d8c2

Please sign in to comment.