All reverse references should be considered multiple.

Steps to reproduce:
1.Create Content type with entity reference field which has setting Allowed number of values set to unlimited.
2.Relate more then one entity to your Content type on your reference field.
3.Enable Reverse entity references processor on index and select for id of referenced entity to index.
4.Try to reindex your index.

Result:
Indexing will fail and if you check logs on solr you should get error like multiple values encountered for non multiValued field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xSDx created an issue. See original summary.

xSDx’s picture

Providing patch for issue

xSDx’s picture

Status: Active » Needs review
mkalkbrenner’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
Status: Needs review » Needs work
+++ b/src/Plugin/search_api/backend/SearchApiSolrBackend.php
@@ -1443,7 +1443,13 @@ class SearchApiSolrBackend extends BackendPluginBase implements SolrBackendInter
+                    $checkForReverseReference = 'search_api_reverse_entity_references';
+                    if (substr($field->getPropertyPath(), 0, strlen($checkForReverseReference)) === $checkForReverseReference) {

I consider this line to be easier ;-)

if (0 === strpos($field->getPropertyPath(), 'search_api_reverse_entity_reference')) {

Beside this, I think the check should happen on top of the getPropertyPathCardinality() function itself.

A test would be great, but I don't know if you can do it?
Maybe there's an existing test in Search API we should simply run on Solr?

xSDx’s picture

I agree. Modified patch and attaching :-).
As for test there is a test in search api module. ReverseEntityReferencesTest.php

xSDx’s picture

Status: Needs work » Needs review
mkalkbrenner’s picture

Title: SearchApiSolrBackground is setting incorrect prefix to Search API reverse entity references » SearchApiSolrBackend is setting incorrect prefix to Search API reverse entity references

Unfortunately there's no integration test in Search API that runs on a real backend.

Ivan616’s picture

Status: Needs review » Reviewed & tested by the community

Applied patch on project after encountering issue.
Issue was appearing when I was setting up Reverse entity references processor and indexing after adding field.

After applying, I managed to index and get correct result.
It worked for me.

  • mkalkbrenner committed ce64691 on 8.x-3.x authored by xSDx
    Issue #3050475 by xSDx, mkalkbrenner: SearchApiSolrBackend is setting...
mkalkbrenner’s picture

Status: Reviewed & tested by the community » Fixed
drunken monkey’s picture

Useful work-around.
However, I think the proper fix would be to also check for $property->isList() in \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getPropertyPathCardinality.
However, this will not fix the problem until #3053603: Entity-typed processor properties don’t support isList() gets committed and becomes available, so for now this workaround definitely makes sense in any case.

drunken monkey’s picture

Status: Fixed » Needs review

Setting back to “Needs review”, but can of course also create a new issue for this.

mkalkbrenner’s picture

@drunken monkey: Should the committed patch be reverted?
Does the call for isList() lead to "undefined function" with the current release of Search API?

drunken monkey’s picture

@drunken monkey: Should the committed patch be reverted?

Once you can depend on the Search API commit being there, yes. (Not sure how you’d determine that – I don’t think a versioned dependency makes sense for just this? Probably just wait a bit, I’d say.)

Does the call for isList() lead to "undefined function" with the current release of Search API?

No, that’s defined right in the Typed Data API, so will always be there. The Search API patch just made it return the correct value for entity-valued processor fields.

mkalkbrenner’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

RoSk0’s picture

Still experiencing this bug with the latest (Search API 8.x-1.14 & Search API Solr 8.x-3.6 ) versions.

Should I open new issue for this ?

dotist’s picture

I'm also getting this error with (Search API 8.x-1.16 & Search API Solr 8.x-3.9).

lukasss’s picture

I get it with Search API 8.x-1.16 & Search API Solr 4.0.1

heathergaye’s picture

I also have this problem, Search API Solr 4.0.0.

Most recent patch doesn't fix, because the field's property_path doesn't match to the property array passed to $this->getPropertyPathCardinality(...), so it drops out of the function with default value 1.

 protected function getPropertyPathCardinality($property_path, array $properties, $cardinality = 1) {
    [$key, $nested_path] = SearchApiUtility::splitPropertyPath($property_path, FALSE);
    if (isset($properties[$key])) { 
      // nope, $key is search_api_reverse_reference... 
      // but $properties contains referencing datasource's properties only
      $property = $properties[$key];

Patch reroll from #5 for version 4.

lukasss’s picture

#21 patch worked for me. TNX

KarlShea’s picture

I think there should be a better way to override this instead of hard-coding for Reverse Entity References. I have a processor that's doing something similar and needs a way of forcing the cardinality to unlimited as well.

KarlShea’s picture

See #3153385 for a possible solution.

mkalkbrenner’s picture

Status: Closed (fixed) » Needs review

Posting patches on a closed issue is a bad idea.

mkalkbrenner’s picture

Version: 8.x-3.x-dev » 4.x-dev
KarlShea’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.