gautamworah96 commented on a change in pull request #2247: URL: https://github.com/apache/lucene-solr/pull/2247#discussion_r566977877
########## File path: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java ########## @@ -353,12 +349,65 @@ public FacetLabel getPath(int ordinal) throws IOException { } synchronized (categoryCache) { - categoryCache.put(catIDInteger, ret); + categoryCache.put(ordinal, ret); } return ret; } + private FacetLabel getPathFromCache(int ordinal) { + ensureOpen(); + + // TODO: can we use an int-based hash impl, such as IntToObjectMap, + // wrapped as LRU? + synchronized (categoryCache) { + FacetLabel res = categoryCache.get(ordinal); + if (res != null) { + return res; + } + } + return null; + } + + /* This API is only supported for indexes created with Lucene 8.7+ codec **/ + public FacetLabel[] getBulkPath(int[] ordinal) throws IOException { + FacetLabel[] bulkPath = new FacetLabel[ordinal.length]; + Map<Integer, Integer> originalPosition = new HashMap<>(); + for (int i = 0; i < ordinal.length; i++) { + if (ordinal[i] < 0 || ordinal[i] >= indexReader.maxDoc()) { + return null; + } + FacetLabel ordinalPath = getPathFromCache(ordinal[i]); + if (ordinalPath != null) { + bulkPath[i] = ordinalPath; + } + originalPosition.put(ordinal[i], i); + } + + Arrays.sort(ordinal); + int readerIndex = 0; + BinaryDocValues values = null; + + for (int ord : ordinal) { + if (bulkPath[originalPosition.get(ord)] == null) { Review comment: It will not be `null` if we already find it in the cache in the initial step i.e the `FacetLabel` for this `ordinal` was found in the cache itself. ---------------------------------------------------------------- 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. 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