Apache Lucene open-source search software
Fix performance bug which skipped cache optimization (early return in DirectoryTaxonomyReader#getBulkOrdinals) (#16783)
Alex Baranov5017142089af
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex e7ada66f4ea..d175ac09747 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -630,6 +630,9 @@ Optimizations* GITHUB#16796: Merges read inner files of compound files through a mapping of their own, so theaccess they advise does not replace the advice of searches. (Jim Ferenczi)+* GITHUB#16783: Fix performance bug in DirectoryTaxonomyReader#getBulkOrdinals that broke its+ ord -> FacetLabel cache such that it always missed when it should have hit. (Alex Baranov)+Bug Fixes---------------------diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.javaindex 0d059814954..6313ff7eb95 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java@@ -354,7 +354,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader implements Accountab}}// all ordinals found in cache- if (indexesMissingFromCache.length == 0) {+ if (numberOfMissingFromCache == 0) {return result;}diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.javaindex 1de1698f255..bc7e1009623 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyReader.java@@ -716,4 +716,22 @@ public class TestDirectoryTaxonomyReader extends FacetTestCase {r1.close();src.close();}++ public void testGetBulkOrdinalsAllCached() throws Exception {+ Directory dir = newDirectory();+ DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);+ FacetLabel a = new FacetLabel("a");+ FacetLabel b = new FacetLabel("b");+ int[] ords = {taxoWriter.addCategory(a), taxoWriter.addCategory(b)};+ taxoWriter.close();++ DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir);+ taxoReader.getBulkOrdinals(a, b); // fills the ordinal cache+ // all ordinals are cached now, so the lookup must not touch the index reader at all+ taxoReader.getInternalIndexReader().close();+ assertArrayEquals(ords, taxoReader.getBulkOrdinals(a, b));++ taxoReader.close();+ dir.close();+ }}