ext-solr icon indicating copy to clipboard operation
ext-solr copied to clipboard

[BUG] In a nested SOLR_RELATION the wrong relation items get indexed

Open pipaltree opened this issue 2 years ago • 1 comments

Describe the bug In a nested relation where the 2nd level relation is an n:m relation the wrong items get indexed when using cObject SOLR_RELATION. As far as I can see this is because when resolving the recursive relation the value from the local field is taken as uid list, but in case of an n:m relation this value contains only the number of relations.

The related code is in class ApacheSolrForTypo3\Solr\ContentObject\Relation in method getRelatedItemsFromForeignTable:

$itemList = $parentContentObject->data[$this->configuration['localField']] ?? '';

$relationHandler->start($itemList, $foreignTableName, '', $localRecordUid, $localTableName, $localFieldTca['config']);
$selectUids = $relationHandler->tableArray[$foreignTableName];

To Reproduce Steps to reproduce the behavior:

  1. Create a table A with an 1:m relation to table B
  2. In table B create an n:m relation to table C
  3. Configure indexing for table A with a multi value field that should contain all relations to table C
  4. Index the records
  5. Look up the indexed values in Solr and see they are wrong

Expected behavior When indexing nested n:m relations the related values should be resolved correctly.

Used versions (please complete the following information):

  • TYPO3 Version: 11.5.4
  • EXT:solr Version: dev-release-11.5.x
  • Used Apache Solr Version: 8.11.1
  • PHP Version: 8.0.13
  • MariaDB Version: 10.5.13

I have seen #2147 describing a similar case but it doesn't fix the issue for me. #2743 is similar too but without n:m relation.

pipaltree avatar Jan 12 '22 09:01 pipaltree

Possible solution could be to also take the TCA setting 'MM' in method getRelatedItemsFromForeignTable into account like:

$itemList = $parentContentObject->data[$this->configuration['localField']] ?? '';
$mmTableName = $localFieldTca['config']['MM'] ?? '';

$relationHandler->start($itemList, $foreignTableName, $mmTableName, $localRecordUid, $localTableName, $localFieldTca['config']);

I tried this in my scenario and it fixed the issue for me.

pipaltree avatar Jan 12 '22 09:01 pipaltree

I confirm the bug but the suggested solution did not fix this for me. In my case the first object relation is a 1:m and the 2nd is a n:m relation.

ulrike-cosmoblonde avatar Dec 22 '22 14:12 ulrike-cosmoblonde

@dkd-friedrich Please port this in 11.5.x

dkd-kaehm avatar Feb 03 '23 11:02 dkd-kaehm

Fixed with https://github.com/TYPO3-Solr/ext-solr/pull/3484 and https://github.com/TYPO3-Solr/ext-solr/pull/3475

dkd-friedrich avatar Feb 10 '23 10:02 dkd-friedrich