Skip to content

Commit

Permalink
EZP-27101: Remove recursion when retrieving search metadata for relat…
Browse files Browse the repository at this point in the history
…ion fields (#1372)

* Fix EZP-27101: Remove recursion when retrieving search metadata

* fixup! Fix EZP-27101: Remove recursion when retrieving search metadata

* fixup! Fix EZP-27101: Remove recursion when retrieving search metadata
  • Loading branch information
natanael89 authored and andrerom committed Jun 29, 2018
1 parent 69c2f36 commit 3539b9c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 30 deletions.
15 changes: 15 additions & 0 deletions doc/bc/5.90/relation_indexing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Relation search indexing changes

For the 2018.06 release, eZ Publish changed the way relations are indexed. Previously the relation metadata was loaded recursively, meaning that relations of relations etc. were also included. This behavior was changed to only include Objects one level deep so only direct relations are taken into account.

The change was done to avoid various recursion problems when relations are circular. Also, the new behavior allows for better (more relevant) search results.

The affected kernel Datatypes are eZObjectRelationType and eZObjectRelationListType.

If you have your custom Datatype that stores relations to other Objects, you can make it behave similarly. Just add the following to your Datatype class:
```php
public function isRelationType()
{
return true;
}
```
24 changes: 11 additions & 13 deletions kernel/classes/datatypes/ezobjectrelation/ezobjectrelationtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function __construct()
array( 'serialize_supported' => true ) );
}

public function isRelationType()
{
return true;
}

/*!
Initializes the class attribute with some data.
*/
Expand Down Expand Up @@ -639,24 +644,17 @@ function metaData( $contentObjectAttribute )
$object = $this->objectAttributeContent( $contentObjectAttribute );
if ( $object )
{
if ( eZContentObject::recursionProtect( $object->attribute( 'id' ) ) )
// Does the related object exist in the same language as the current content attribute ?
if ( in_array( $contentObjectAttribute->attribute( 'language_code' ), $object->attribute( 'current' )->translationList( false, false ) ) )
{
// Does the related object exist in the same language as the current content attribute ?
if ( in_array( $contentObjectAttribute->attribute( 'language_code' ), $object->attribute( 'current' )->translationList( false, false ) ) )
{
$attributes = $object->attribute( 'current' )->contentObjectAttributes( $contentObjectAttribute->attribute( 'language_code' ) );
}
else
{
$attributes = $object->contentObjectAttributes();
}

return eZContentObjectAttribute::metaDataArray( $attributes );
$attributes = $object->attribute( 'current' )->contentObjectAttributes( $contentObjectAttribute->attribute( 'language_code' ) );
}
else
{
return array();
$attributes = $object->contentObjectAttributes();
}

return eZContentObjectAttribute::metaDataArray( $attributes, true );
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function __construct()
array( 'serialize_supported' => true ) );
}

public function isRelationType()
{
return true;
}

/*!
Validates the input and returns true if the input was
valid for this datatype.
Expand Down Expand Up @@ -1616,17 +1621,14 @@ function metaData( $contentObjectAttribute )
$subObjectVersionNum = $subCurrentVersionObject->attribute( 'version' );
}

if ( eZContentObject::recursionProtect( $subObjectID ) )
if ( !$subObject )
{
if ( !$subObject )
{
continue;
}
$attributes = $subObject->contentObjectAttributes( true, $subObjectVersionNum, $language );
continue;
}
$attributes = $subObject->contentObjectAttributes( true, $subObjectVersionNum, $language );
}

$attributeMetaDataArray = eZContentObjectAttribute::metaDataArray( $attributes );
$attributeMetaDataArray = eZContentObjectAttribute::metaDataArray( $attributes, true );
$metaDataArray = array_merge( $metaDataArray, $attributeMetaDataArray );
}

Expand Down
28 changes: 18 additions & 10 deletions kernel/classes/ezcontentobjectattribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,26 +1168,34 @@ function fromString( $string )
Goes trough all attributes and fetches metadata for the ones that is searchable.
\return an array with metadata information.
*/
static function metaDataArray( &$attributes )
static function metaDataArray( &$attributes, $skipRelationAttributes = false )
{
$metaDataArray = array();
if ( !is_array( $attributes ) )
return false;
foreach( $attributes as $attribute )
{
$classAttribute = $attribute->contentClassAttribute();
if ( $classAttribute->attribute( 'is_searchable' ) )
if ( !$classAttribute->attribute( 'is_searchable' ) )
{
$attributeMetaData = $attribute->metaData();
if ( $attributeMetaData !== false )
continue;
}

$datatype = $attribute->dataType();
if ( $skipRelationAttributes && $datatype->isRelationType() )
{
continue;
}

$attributeMetaData = $datatype->metaData($attribute);
if ( $attributeMetaData !== false )
{
if ( !is_array( $attributeMetaData ) )
{
if ( !is_array( $attributeMetaData ) )
{
$attributeMetaData = array( array( 'id' => '',
'text' => $attributeMetaData ) );
}
$metaDataArray = array_merge( $metaDataArray, $attributeMetaData );
$attributeMetaData = array( array( 'id' => '',
'text' => $attributeMetaData ) );
}
$metaDataArray = array_merge( $metaDataArray, $attributeMetaData );
}
}
return $metaDataArray;
Expand Down
10 changes: 10 additions & 0 deletions kernel/classes/ezdatatype.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ function isSimpleStringInsertionSupported()
return false;
}

/**
* Indicates if the datatype handles relations
*
* @return bool
*/
public function isRelationType()
{
return false;
}

/*!
\virtual
Inserts the HTTP file \a $httpFile to the content object attribute \a $objectAttribute.
Expand Down

0 comments on commit 3539b9c

Please sign in to comment.