Ivan Hrytsyuk created SOLR-4880:
-----------------------------------
Summary: ClientUtils#toSolrInputDocument(SolrDocument d) creates
shallow copy for multivalued fields
Key: SOLR-4880
URL: https://issues.apache.org/jira/browse/SOLR-4880
Project: Solr
Issue Type: Bug
Components: clients - java
Reporter: Ivan Hrytsyuk
Fix For: 3.6
Multivalued fields are represented in SolrDocument as java.util.Collection.
ClientUtils#toSolrInputDocument(SolrDocument d) creates shallow copy of the
collections in resulted SolrInputDocument.
That means that changes to resulted instance (i.e. adding/removing records)
affect original instance as well, which is bad.
*Expected Behaviour*: Deep copy of collections should be created. Changes to
resulted instance shouldn't affect original instance
*Possible Implementation*:
{code:java}
public static SolrInputDocument toSolrInputDocument(final SolrDocument
solrDocument) {
final Map<String,SolrInputField> fields = new
LinkedHashMap<String,SolrInputField>();
return toSolrInputDocument(solrDocument, fields);
}
public static SolrInputDocument toSolrInputDocument(final SolrDocument
solrDocument, final Map<String,SolrInputField> fields) {
final SolrInputDocument result = new SolrInputDocument(fields);
for(final Map.Entry<String, Object> entry : solrDocument.entrySet()) {
if(entry.getValue() instanceof Collection) {
result.setField(entry.getKey(), new
ArrayList<Object>((Collection<Object>) entry.getValue()));
} else {
result.setField(entry.getKey(), entry.getValue());
}
}
return result;
}
{code}
*Note*: Believe the same issue is true for
ClientUtils#toSolrDocument(SolrInputDocument d)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]