Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] In a recursive SOLR_RELATION only one element from tt_content gets indexed into the solr core #2743

Closed
haraldwitt opened this issue Oct 7, 2020 · 13 comments
Assignees

Comments

@haraldwitt
Copy link
Contributor

haraldwitt commented Oct 7, 2020

I have a custom table "offers" which contains a field "product_uid" pointing to the product table.
I have the other custom table "products" with the field "content_elements" pointing to tt_content.
"content_elements" is an inline element in the same manner tx_news it does.
Now I want to index the content elements as SOLR_CONTENT with an indexing configuration for "offers". Why that? The reason is, that "offers" contains an endtime-field which is very important for the search results!
My index configuration looks as follows:

plugin.tx_solr.index.queue {
	offers = 1
	offers {
		table = offers
		fields {
			...
			content = SOLR_CONTENT
			content.cObject = COA
			content.cObject {
				20 = SOLR_RELATION
				20 {
					localField = product_uid
					foreignLabelField = content_elements.bodytext
					singleValueGlue = | |
				}
			}
			...
		}
	}
}

Using this, only the bodytext of the LAST related record of tt_content will appear in the content-field of the solr core_de.

But when indexing "products", the bodytext of ALL related records will be found in the solr core_de.
The configuration for products:

plugin.tx_solr.index.queue {
	products = 1
	products {
		table = products
		fields {
			...
			content = SOLR_CONTENT
			content {
				cObject = COA
				cObject {
					10 = SOLR_RELATION
					10 {
						localField = content_elements
						foreignLabelField = bodytext
						singleValueGlue = | |
					}
				}
			}
			...
		}
	}
}

But this is not suittable for me because of the missing endtime-field in products.

@haraldwitt
Copy link
Contributor Author

haraldwitt commented Oct 7, 2020

Ok, I found issue #2147 but this is NOT a duplicate.
In my case "content_elements" points NOT to a MM-table, BUT to a foreign_table with foreign_field.
As I already debugged, getRelatedItemsFromForeignTable() deleivers the correct records. But they are not going into the core.

@haraldwitt
Copy link
Contributor Author

haraldwitt commented Oct 7, 2020

Ok, I got it!

Class: ApacheSolrForTypo3\Solr\ContentObject\Relation
Line 325++
Method: resolveRelatedValue

There you con find the following:

            // recursion
            $relatedItemsFromForeignTable = $this->getRelatedItemsFromForeignTable(
                $foreignTableName,
                $relatedRecord['uid'],
                $foreignTableTca['columns'][$foreignTableLabelField],
                $parentContentObject
            );
            $value = array_pop($relatedItemsFromForeignTable);

Obviously the array_pop() makes the problem.
I replaced array_pop()-line with the following:

            $singleValueGlue = !empty($this->configuration['singleValueGlue']) ? trim($this->configuration['singleValueGlue'], '|') : ', ';
            $value = implode($singleValueGlue, $relatedItemsFromForeignTable);

And now all functions as expected!
Hope this Bugfix will be accepted :-)

@haraldwitt
Copy link
Contributor Author

haraldwitt commented Oct 8, 2020

The better way is to respect also the multiValue parameter of SOLR_RELATION:

	if (empty($this->configuration['multiValue'])) {
		// single value, need to concatenate related items
		$singleValueGlue = !empty($this->configuration['singleValueGlue']) ? trim($this->configuration['singleValueGlue'], '|') : ', ';
		$value = implode($singleValueGlue, $relatedItemsFromForeignTable);
	} else {
		// multi value, need to serialize as content objects must return strings
		$value = serialize($relatedItemsFromForeignTable);
	}

Greetings
Harald

@dkd-kaehm
Copy link
Collaborator

@haraldwitt thanks for reporting this issue.
Could you please provide a Pull-Request?
Wee need a tests to reproduce this, could you please provide the test case or at least the fixture?

@haraldwitt
Copy link
Contributor Author

haraldwitt commented Oct 8, 2020

Hi @dkd-kaehm,
now I've created a Pull-Request. But I haven't a clue on how to write a test or a fixture :-(
But the code is neatly the same like in the method render() in line 108, except I was using $this->configuration instead of $conf.

@dkd-kaehm
Copy link
Collaborator

@haraldwitt
Thanks for PR.
We'll provide a tests for this case.

@dkd-kaehm dkd-kaehm self-assigned this Oct 9, 2020
@cehret
Copy link

cehret commented Oct 17, 2020

I had the same issue:

I have a model "section" with an inline relation to recipe. The "recipe" model has an inline relation to ingredient:

section -> recipe -> ingredient

without the bugfix this does not work:


    section {
        additionalPageIds = 123
        table = tx_toco3ext_domain_model_section
        fields {
....
            content = SOLR_CONTENT
            content {
                cObject = COA
                cObject {`
                    120 = SOLR_RELATION
                    120 {
                        localField = recipe
                        foreignLabelField = ingredients.ingredient.title
                    }
          }
   }
}

I get only one in ingredient!
but if I start one level "deeper" it works:

    recipe {
        additionalPageIds = 123
        table = tx_toco3ext_domain_model_recipe
        fields {

            content = SOLR_CONTENT
            content {
                cObject = COA
                cObject {

                    10 = SOLR_RELATION
                    10{
                        localField = ingredients
                        foreignLabelField = ingredient.title
                        multiValue = 1
                    }
                }
            }

        }

here I get all ingredients.

After applying your Bugfix the first code also returns all ingredients!!

@dkd-kaehm
Copy link
Collaborator

@toco3 and @haraldwitt please checkout the latest state and give a feedback.
We want integration test cases for this PR anyway.

@dkd-kaehm
Copy link
Collaborator

@haraldwitt FYI Your #2745 pull request is gone, because of fork deletion.

@dkd-kaehm
Copy link
Collaborator

@haraldwitt, @cehret
This issue is most probably fixed by #3484 for TYPO3 11.5 and by #3475 for TYPO3 12.4.
Please confirm the functionality.

@haraldwitt
Copy link
Contributor Author

@dkd-kaehm
Oh, I'm sorry. I totally forgot this 3 year old PR. But I'll check this issue in 11.5 again.

@haraldwitt
Copy link
Contributor Author

@dkd-kaehm
Ok, I checked this again. All seems to function as it should.
So you can close this issue :-)
Harald

@dkd-kaehm
Copy link
Collaborator

@haraldwitt Top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants