diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index f834946715f..05df765f1cb 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -31,6 +31,10 @@ API Changes and exposes Iterator, so you can iterate over field names with for (String field : fields) instead. (Robert Muir) +* LUCENE-4152: added IndexReader.leaves(), which lets you enumerate + the leaf atomic reader contexts for all readers in the tree. + (Uwe Schindler, Robert Muir) + Bug Fixes * LUCENE-4297: BooleanScorer2 would multiply the coord() factor diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexReader.java b/lucene/core/src/java/org/apache/lucene/index/IndexReader.java index 59b6e911929..3fe1c659dbe 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexReader.java @@ -21,6 +21,7 @@ import java.io.Closeable; import java.io.IOException; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; import java.util.WeakHashMap; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -396,6 +397,13 @@ public abstract class IndexReader implements Closeable { * @lucene.experimental */ public abstract IndexReaderContext getTopReaderContext(); + + /** + * Returns the reader's leaves, or itself if this reader is Atomic. + */ + public final List leaves() { + return getTopReaderContext().leaves(); + } /** Expert: Returns a key for this IndexReader, so FieldCache/CachingWrapperFilter can find * it again.