xande commented on code in PR #12769:
URL: https://github.com/apache/lucene/pull/12769#discussion_r4199768694
##########
lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java:
##########
@@ -312,6 +316,117 @@ public int getOrdinal(FacetLabel cp) throws IOException {
return ret;
}
+ @Override
+ public int[] getBulkOrdinals(FacetLabel... categoryPaths) throws IOException
{
+ ensureOpen();
+ if (categoryPaths.length == 0) {
+ return new int[0];
+ }
+ if (categoryPaths.length == 1) {
+ return new int[] {getOrdinal(categoryPaths[0])};
+ }
+ // First try to find results in the cache:
+ int[] result = new int[categoryPaths.length];
+ int[] indexesMissingFromCache = new int[10]; // initial size, will grow
when required
+ int numberOfMissingFromCache = 0;
+ FacetLabel cp;
+ Integer res;
+ for (int i = 0; i < categoryPaths.length; i++) {
+ cp = categoryPaths[i];
+ synchronized (ordinalCache) {
+ res = ordinalCache.get(cp);
+ }
+ if (res != null) {
+ if (res < indexReader.maxDoc()) {
+ // Since the cache is shared with DTR instances allocated from
+ // doOpenIfChanged, we need to ensure that the ordinal is one that
+ // this DTR instance recognizes.
+ result[i] = res;
+ } else {
+ // if we get here, it means that the category was found in the cache,
+ // but is not recognized by this TR instance. Therefore, there's no
+ // need to continue search for the path on disk, because we won't
find
+ // it there too.
+ result[i] = TaxonomyReader.INVALID_ORDINAL;
+ }
+ } else {
+ indexesMissingFromCache =
+ ArrayUtil.grow(indexesMissingFromCache, numberOfMissingFromCache +
1);
+ indexesMissingFromCache[numberOfMissingFromCache++] = i;
+ }
+ }
+ // all ordinals found in cache
+ if (indexesMissingFromCache.length == 0) {
Review Comment:
With AI pocking around the code, I found that this condition never passes.
Fix: https://github.com/apache/lucene/pull/16783
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]