Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a node reference field that allows multiple values, but when I tried to index it, single index is created, which causes errors in solr:
org.apache.solr.common.SolrException: ERROR: [doc=ohhv8s/node/8872] multiple values encountered for non multiValued field is_field_category: [8161, 1]
Comments
Comment #1
Nick_vhWhat version of Solr are you using? I've encountered this with Solr 4. I've seen this happening with hierarchic taxonomy fields. Can you try latest dev version and see if it is resolved? (patched something about this problem last weekend)
Comment #2
Nick_vhapachesolr_nodereference_indexing_callback should probably check if the field is single valued and only allow 1 value if that is the case.
Could one of you tell me what is in the $field_info for your specific case?
Comment #3
remimikalsen CreditAttribution: remimikalsen commentedI'm using 7.x-1.1 regularly and it seems 7.x-1.x-dev (downloaded today) introduces a bug on entity-reference to taxonomy terms. I have a field that is an entity-reference to an unlimited number of taxonomy terms of a particular vocabulary. The apachesolr status page for facets identifies the field as an ss_ field, but it's attemted indexed as an sm_ field (which of course fails terribly on the solr-side). Solr 3.6 here, but it's really not a Solr problem.
I'll try to be more explicit on the nature of this bug when I have some time on my hands. For now I'll just have to "put it out there".
R
Comment #4
Nick_vhNo time is no excuse, really. Just put a debug statement there and paste it here. :)
Comment #5
remimikalsen CreditAttribution: remimikalsen commented* apachesolr_entityreference_indexing_callback
* dd($field_info);
Gives:
(Note the multiple field; here it holds nothing. The stable version holds "1")
Comment #6
Nick_vhSo 'multiple' seems to be false, apachesolr correctly gives it a singular field. I assume that the assignment of entityreference keys is done incorrectly somehow.
Could you also do a debug of the apachesolr_entity_fields();function? Perhaps we have to force all reference fields to be multiple in any case?
Comment #7
remimikalsen CreditAttribution: remimikalsen commentedIn apachesolr_entity_fields() there is:
Append immediately after:
Solves it for me. Maybe the !==0 is redundant. In any case, cardinality -1 or >1 are the multiples.
Comment #8
Nick_vhInteresting, could you make a patch? And add some documentation about the cardinality field.
eg.: cardinality (integer): The number of values the field can hold. Legal values are any positive integer or FIELD_CARDINALITY_UNLIMITED.
http://api.drupal.org/api/drupal/modules%21field%21field.module/group/fi...
So it's only when the value == 1, we should set a field to single. -1 is unlimited and anything else means multiple. I'm not sure what 0 does. Also, we might want to rename multiple throughout the codebase to cardinality to sync more with D7?
Comment #9
remimikalsen CreditAttribution: remimikalsen commentedSee attached patch.
Comment #10
Nick_vhWe also want to check if the field is set, so you can do an isset($field['cardinality]) && $field['cardinality'] !== 1
Comment #11
remimikalsen CreditAttribution: remimikalsen commentedAttached patch v2.
I assumed it must hold positive integer or FIELD_CARDINALITY_UNLIMITED, but better safe than sorry; guess an isset doesn't "cost" all that much.
Comment #12
ianthomas_ukIs there a reason to use !== instead of just !=? Are we sure it will never be '1'?
Setting to needs review to get picked up by automated tests.
Comment #13
remimikalsen CreditAttribution: remimikalsen commentedI'm not sure of that, But if a '1' is found, maybe it should be fixed by the code that violates the documented behaviour?
R
Comment #14
Nick_vhYou can just use !=, makes it less strict, but more certain that even custom code will be picked up.
Comment #15
remimikalsen CreditAttribution: remimikalsen commentedComment #16
Nick_vhComment #17
mkalkbrennerSomething similar here:
In our case, field_testimonial is a multi value entity reference on a node.
#15 solved the issue.
Comment #18
albert78 CreditAttribution: albert78 commentedPatch from #15 solved my issue as well.
Comment #19
steven.wichers CreditAttribution: steven.wichers commentedAlso confirming #15 seems to have fixed the issue for us.
Comment #20
swentel CreditAttribution: swentel commentedBeen bitten by this as well. Rerolled for 80 chars limit and removed the isset(). @nick, field api adds defaults, also for cardinality (defaults to 1), so the property is always set. Still RTBC.
Comment #21
swentel CreditAttribution: swentel commentedBAH
Comment #22
Nick_vhNot sure if it needs backport, but marking as such until someone confirms. Committed to 7.x-1.x
Comment #23
wonder95 CreditAttribution: wonder95 commentedAttached is a patch for a backport to 6.x-3.x.
Comment #24
wonder95 CreditAttribution: wonder95 commentedComment #25
Nick_vhDrupal 6 does not have the cardinality config, only multiple. So due to that it is not applicable and I am going to close this issue.