Github user dsmiley commented on a diff in the pull request: https://github.com/apache/lucene-solr/pull/416#discussion_r205126064 --- 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 -- Ah, I see (I didn't look at Multimap's iteration options when I wrote that). Your code here is good.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org