Github user dsmiley commented on a diff in the pull request:

    https://github.com/apache/lucene-solr/pull/455#discussion_r223747455
  
    --- 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;
    +      Collection<Object> fieldValues = fullDoc.getFieldValues(fieldName);
    +      if(fieldValues.size() < subSif.getValueCount()) return false;
    +      
if(!fullDoc.getFieldValues(fieldName).containsAll(subSif.getValues())) return 
false;
    --- End diff --
    
    `fullDoc.getFieldValues(fieldName)` on this line can be replaced by 
`fieldValues` since we already have the values.  And the previous line on the 
count is unnecessary since the containsAll check on this line would fail.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to