Github user dsmiley commented on a diff in the pull request:
https://github.com/apache/lucene-solr/pull/455#discussion_r223747918
--- Diff:
solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateDocumentMerger.java
---
@@ -442,5 +442,58 @@ protected void doRemoveRegex(SolrInputDocument toDoc,
SolrInputField sif, Object
}
return patterns;
}
+
+ private Object getNativeFieldValue(String fieldName, Object val) {
+ if(isChildDoc(val)) {
+ return val;
+ }
+ SchemaField sf = schema.getField(fieldName);
+ return sf.getType().toNativeType(val);
+ }
+
+ private static boolean isChildDoc(Object obj) {
+ if(!(obj instanceof Collection)) {
+ return obj instanceof SolrDocumentBase;
+ }
+ Collection objValues = (Collection) obj;
+ if(objValues.size() == 0) {
+ return false;
+ }
+ return objValues.iterator().next() instanceof SolrDocumentBase;
+ }
+
+ private void removeObj(Collection original, Object toRemove, String
fieldName) {
+ if(isChildDoc(toRemove)) {
+ removeChildDoc(original, (SolrInputDocument) toRemove);
+ } else {
+ original.remove(getNativeFieldValue(fieldName, toRemove));
+ }
+ }
+
+ private static void removeChildDoc(Collection original,
SolrInputDocument docToRemove) {
+ for(SolrInputDocument doc: (Collection<SolrInputDocument>) original) {
+ if(isDerivedFromDoc(doc, docToRemove)) {
+ original.remove(doc);
+ return;
+ }
+ }
+ }
+
+ /**
+ *
+ * @param fullDoc the document to be tested
+ * @param subDoc the sub document that should be a subset of fullDoc
+ * @return whether subDoc is a subset of fullDoc
+ */
+ private static boolean isDerivedFromDoc(SolrInputDocument fullDoc,
SolrInputDocument subDoc) {
+ for(SolrInputField subSif: subDoc) {
+ String fieldName = subSif.getName();
+ if(!fullDoc.containsKey(fieldName)) return false;
--- End diff --
This results in a double-lookup of the values with the next line. Remove
this line and after the next one simply do a null-check.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]