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

    https://github.com/apache/lucene-solr/pull/416#discussion_r205124868
  
    --- Diff: 
solr/core/src/java/org/apache/solr/response/transform/DeeplyNestedChildDocTransformer.java
 ---
    @@ -132,54 +126,49 @@ public void transform(SolrDocument rootDoc, int 
rootDocId) {
                 // load the doc
                 SolrDocument doc = 
DocsStreamer.convertLuceneDocToSolrDoc(docFetcher.doc(docId),
                     schema, new SolrReturnFields());
    -            doc.setField(NEST_PATH_FIELD_NAME, fullDocPath);
                 if (shouldDecorateWithDVs) {
                   docFetcher.decorateDocValueFields(doc, docId, 
dvFieldsToReturn);
                 }
                 // get parent path
                 // put into pending
                 String parentDocPath = lookupParentPath(fullDocPath);
    -            pendingParentPathsToChildren.put(parentDocPath, doc); // 
multimap add (won't replace)
     
    -            // if this path has pending child docs, add them.
    -            if (isAncestor) {
    -              addChildrenToParent(doc, 
pendingParentPathsToChildren.get(fullDocPath));
    -              pendingParentPathsToChildren.removeAll(fullDocPath); // no 
longer pending
    +            if(isAncestor) {
    +              // if this path has pending child docs, add them.
    +              addChildrenToParent(doc, 
pendingParentPathsToChildren.remove(fullDocPath)); // no longer pending
                 }
    +            pendingParentPathsToChildren.computeIfAbsent(parentDocPath, x 
-> ArrayListMultimap.create())
    +                .put(trimIfSingleDoc(getLastPath(fullDocPath)), doc); // 
multimap add (won't replace)
               }
             }
     
             // only children of parent remain
             assert pendingParentPathsToChildren.keySet().size() == 1;
     
    -        addChildrenToParent(rootDoc, 
pendingParentPathsToChildren.get(null));
    +        addChildrenToParent(rootDoc, 
pendingParentPathsToChildren.remove(null));
           }
         } catch (IOException e) {
           rootDoc.put(getName(), "Could not fetch child Documents");
         }
       }
     
    -  void addChildToParent(SolrDocument parent, SolrDocument child, String 
label) {
    -    // lookup leaf key for these children using path
    -    // depending on the label, add to the parent at the right key/label
    -    // TODO: unfortunately this is the 2nd time we grab the paths for 
these docs. resolve how?
    -    String trimmedPath = trimSuffixFromPaths(getLastPath(label));
    -    if (!parent.containsKey(trimmedPath) && (label.contains(NUM_SEP_CHAR) 
&& !label.endsWith(NUM_SEP_CHAR))) {
    -      List<SolrDocument> list = new ArrayList<>();
    -      parent.setField(trimmedPath, list);
    +  void addChildrenToParent(SolrDocument parent, Multimap<String, 
SolrDocument> children) {
    +    for(String childLabel: children.keySet()) {
    --- End diff --
    
    it seems like MultiMap entries are not returned as the collections for each 
key, but are instead returned as entries with each key added to it. It seems 
more efficient to add the whole array at once, reducing the amount of lookups 
that have to be made for each child. We could do this in one simple look up.


---

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

Reply via email to