Skip to content

Commit

Permalink
Merge pull request IQSS#11136 from vera/fix/9200-allowmultiples-for-d…
Browse files Browse the repository at this point in the history
…eep-nesting

fix: correctly set "multiValued" property in Solr schema for deeply nested fields
  • Loading branch information
ofahimIQSS authored Feb 4, 2025
2 parents 25b3f6e + a236d5c commit aebec05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/11136-solr-nested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deeply nested metadata fields are not supported but the code used to generate the Solr schema has been adjusted to support them. See #11136.
21 changes: 15 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/DatasetFieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,17 +541,26 @@ public SolrField getSolrField() {
solrType = SolrField.SolrType.FLOAT;
}

Boolean parentAllowsMultiplesBoolean = false;
if (isHasParent()) {
if (getParentDatasetFieldType() != null) {
DatasetFieldType parent = getParentDatasetFieldType();
parentAllowsMultiplesBoolean = parent.isAllowMultiples();
Boolean anyParentAllowsMultiplesBoolean = false;
DatasetFieldType currentDatasetFieldType = this;
// Traverse up through all parents of dataset field type
// If any one of them allows multiples, this child's Solr field must be multi-valued
while (currentDatasetFieldType.isHasParent()) {
if (currentDatasetFieldType.getParentDatasetFieldType() != null) {
DatasetFieldType parent = currentDatasetFieldType.getParentDatasetFieldType();
if (parent.isAllowMultiples()) {
anyParentAllowsMultiplesBoolean = true;
break; // no need to keep traversing
}
currentDatasetFieldType = parent;
} else {
break;
}
}

boolean makeSolrFieldMultivalued;
// http://stackoverflow.com/questions/5800762/what-is-the-use-of-multivalued-field-type-in-solr
if (allowMultiples || parentAllowsMultiplesBoolean || isControlledVocabulary()) {
if (allowMultiples || anyParentAllowsMultiplesBoolean || isControlledVocabulary()) {
makeSolrFieldMultivalued = true;
} else {
makeSolrFieldMultivalued = false;
Expand Down

0 comments on commit aebec05

Please sign in to comment.