Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
Description
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:
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; }
Note: Believe the same issue is true for ClientUtils#toSolrDocument(SolrInputDocument d)