Yuti-G commented on a change in pull request #747: URL: https://github.com/apache/lucene/pull/747#discussion_r829346533
########## File path: lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java ########## @@ -414,4 +505,101 @@ public int compare(FacetResult a, FacetResult b) { return results; } + + @Override + public List<FacetResult> getTopDims(int topNDims, int topNChildren) throws IOException { + // Creates priority queue to store top dimensions and sort by their aggregated values/hits and + // string values. + PriorityQueue<SortedSetDocValuesDimValueResult> pq = + new PriorityQueue<>(topNDims) { + @Override + protected boolean lessThan( + SortedSetDocValuesDimValueResult a, SortedSetDocValuesDimValueResult b) { + if (a.value.intValue() > b.value.intValue()) { + return false; + } else if (a.value.intValue() < b.value.intValue()) { + return true; + } else { + return a.dim.compareTo(b.dim) > 0; + } + } + }; + + HashMap<String, SortedSetDocValuesChildOrdsResult> cacheChildOrdsResult = new HashMap<>(); + + for (String dim : state.getDims()) { + FacetsConfig.DimConfig dimConfig = stateConfig.getDimConfig(dim); + if (dimConfig.hierarchical) { + DimTree dimTree = state.getDimTree(dim); + int dimOrd = dimTree.dimStartOrd; + // get dim value + int dimCount = + getDimValue( + dimConfig, dim, dimOrd, dimTree.iterator(), topNChildren, cacheChildOrdsResult); + if (dimCount != 0) { + // use priority queue to store SortedSetDocValuesDimValueResult for topNDims + pq.insertWithOverflow(new SortedSetDocValuesDimValueResult(dim, dimCount)); + } + } else { + OrdRange ordRange = state.getOrdRange(dim); + int dimOrd = ordRange.start; + PrimitiveIterator.OfInt childIt = ordRange.iterator(); + if (dimConfig.multiValued && dimConfig.requireDimCount) { + // If the dim is multi-valued and requires dim counts, we know we've explicitly indexed + // the dimension and we need to skip past it so the iterator is positioned on the first + // child: + childIt.next(); + } + int dimCount = + getDimValue(dimConfig, dim, dimOrd, childIt, topNChildren, cacheChildOrdsResult); + if (dimCount != 0) { + pq.insertWithOverflow(new SortedSetDocValuesDimValueResult(dim, dimCount)); + } + } + } + + // get FacetResult for topNDims + List<FacetResult> results = new LinkedList<>(); + while (pq.size() > 0) { + SortedSetDocValuesDimValueResult dimValueResult = pq.pop(); + if (dimValueResult != null) { + FacetResult factResult = + getFacetResultForDim(dimValueResult.dim, topNChildren, cacheChildOrdsResult); + if (factResult != null) { Review comment: Ah.. sorry, I forgot to remove the null checks after changing the return type from `Number` to `int` in getDimValue. I will address this issue in the new commit. Thank you! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org