TYPO3-Solr / ext-solr

A TYPO3 extension that integrates the Apache Solr search server with TYPO3 CMS. dkd Internet Service GmbH is developing the extension. Community contributions are welcome. See CONTRIBUTING.md for details.
GNU General Public License v3.0
136 stars 246 forks source link

[BUG] SOLR_RELATION with subproperty in foreignLabelField always resolves the field defined as labelfield in TCA (ignoring the Typoscript Configuration) #3993

Open jonnsn opened 3 months ago

jonnsn commented 3 months ago

Describe the bug A field of type SOLR_RELATION with enableRecursiveValueResolution = 1 and having a foreignLabelField with a subproperty (dot-notation) will always resolve the Label Field defined via TCA instead of the field, defined in the Typoscript property foreignLabelField.

To Reproduce Steps to reproduce the behavior:

  1. use solr-ddev-site
  2. create a sys_category named "cat 1" with any description
  3. create a second sys_category named "cat 2" with "cat 1" as parent.
  4. create or modify a tt_content and set "cat 2" as category
  5. use the following typoscript
    plugin.tx_solr {
    index {
    queue {
      myDataSet = 1
      myDataSet {
        table = tt_content
        fields{
          title = header
          content = SOLR_RELATION
          content {
            enableRecursiveValueResolution = 1
            localField = categories
            foreignLabelField = parent.description
            singleValueGlue = | |
          }
        }
      }
    }
    }
    }
  6. index your content
  7. check the content via SOLR admin The SOLR Field "content" for the modified record contains "cat 1" (the title of sys_category entered in step 2).

Expected behavior the SOLR Field "content" for the modified record should contain the description of "cat 1" entered in step 2.

Used versions (please complete the following information): (from current solr-ddev-site)

Additional context removing ext:solr/Classes/ContentObject/Relation.php:178 unset($this->configuration['foreignLabelField']); solves the problem. But I am unsure why this line is needed. Thats why I did not provide a patch. The line was added with https://github.com/TYPO3-Solr/ext-solr/pull/3484/files.

dkd-friedrich commented 3 months ago

I can confirm the error described, but unfortunately the problem is more complex. Removing the line mentioned unfortunately generates errors in other scenarios, I'm afraid we'll have to refactor SOLR_RELATION.

I can't remember the background of the change back then, a special format is used in the tests, if on purpose or by mistake, I can't say spontaneously.

In the meantime, the definition of an additional segment could be used as a workaround: foreignLabelField = parent.title.description

jonnsn commented 3 months ago

@dkd-friedrich Thanks for investigating. I do not really get the workaround. I want parent.description. Your Workaround suggests to add ".title" in that path, so it becomes parent.title.description. Right? This does not seem to work for me unfortunately.

dkd-friedrich commented 2 months ago

@dkd-friedrich Thanks for investigating. I do not really get the workaround. I want parent.description. Your Workaround suggests to add ".title" in that path, so it becomes parent.title.description. Right? This does not seem to work for me unfortunately.

@jonnsn ok, my test case might be wrong.

Unfortunately, I can't dive deeper into the topic at the moment, but I have pushed my extended integration test, perhaps that will help: => https://github.com/TYPO3-Solr/ext-solr/commit/f91b81b15a1c18dd683a660b4fb723c7e24ad163

In my test case, it was sufficient to use "parent.xxx.description" instead of "parent.description" for "foreignLabelField".

jonnsn commented 2 months ago

@dkd-friedrich Thanks for your hints.

I can confirm your Workaround works - if there is only one Item in $relatedRecords.

If you extend my steps to reproduce from above by replacing steps 3 and 4 with the following:

  1. create a second sys_category named "cat 2" with "cat 1" as parent.
  2. create a third sys_category named "cat 3" with "cat 1" as parent.
  3. create or modify a tt_content and set "cat 2" and "cat 3" as category

then it will work (with your workaround active) for the first of the categories, but every following record will have title instead of description in the index. This is because $this->configuration['foreignLabelField'] is set to the remaining part already and therefore does not contain any '.' anymore on the next foreach ($relatedRecords as $record) run.

So combining it with your workaround I can patch the code quick and dirty as follows to get it working for me: \ApacheSolrForTypo3\Solr\ContentObject\Relation::getRelatedItemsFromMMTable replace foreach ($relatedRecords as $record) { with

        $originalForeignLabelField = $this->configuration['foreignLabelField'];
        foreach ($relatedRecords as $record) {
            $this->configuration['foreignLabelField'] = $originalForeignLabelField;

unfortunately I could not get the tests to work in my solr-ddev-site instance, so I could not test the change...