Problem/Motivation
The current code makes all fields multi-valued by default in apachesolr_get_field_mappings()
// Field API allows any field to be multi-valued.
'multiple' => TRUE,
This renders void the ability to sort on a single-valued field which seems an undesirable side effect to say the least. While the comment correctly points out that any field may be multi-valued, its use as a default is harmful.
The following code in apachesolr_entity_fields()
gives the impression that it is changing the 'multiple' key to TRUE if cardinality != 1. However, because of the default being TRUE, this code is of no effect (save a contributed or custom module had overwritten this default).
if ($row['field']['cardinality'] != 1) {
$row['multiple'] = TRUE;
}
Proposed resolution
Set 'multiple' key in search field information based on field cardinality.
Remaining tasks
Reveiew and test.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#2 | apachesolr-2617448-2-set-multiple-key.patch | 1.65 KB | solotandem |
Comments
Comment #2
solotandem CreditAttribution: solotandem commentedAttached patch implements proposed resolution.
Comment #3
q0rban CreditAttribution: q0rban at Lullabot commentedThis issue can cause some interesting bugs. For example, if you assume a bs_ prefixed (boolean, single value) solr document field is what it says it is, you may do a simple if statement on the field without realizing that it is an array of
array(0 => 0)
, which would evaluate toTRUE
.The previously attached patch doesn't fix the whole problem. In field_apachesolr_index_document_build(), $document->setMultiValue() is used for all fields with the comment "// It's fine to use this method also for single value fields."
Comment #4
solotandem CreditAttribution: solotandem commentedWhat does what you wrote have to do with this issue? You make statements but what is their point?
Comment #5
q0rban CreditAttribution: q0rban at Lullabot for Cisco Systems commentedMy points are:
field_apachesolr_index_document_build()
calls$document->setMultiValue()
, without checking if the field is multiple or not.:)