salvatorecampagna commented on code in PR #15378:
URL: https://github.com/apache/lucene/pull/15378#discussion_r2482348482
##########
lucene/core/src/java/org/apache/lucene/index/MergePolicy.java:
##########
@@ -939,4 +939,96 @@ static final class MergeReader {
this.hardLiveDocs = hardLiveDocs;
}
}
+
+ /**
+ * Observer for merge operations returned by {@link
IndexWriter#forceMergeDeletes(boolean)}.
+ * Provides methods to query merge status and wait for completion.
+ *
+ * <p>When no merges are needed, {@link #hasNewMerges()} returns {@code
false} and {@link
+ * #numMerges()} returns 0. In this case, {@link #await()} returns {@code
true} immediately since
+ * there is nothing to wait for.
+ *
+ * @lucene.experimental
+ */
+ public static final class MergeObserver {
+ private final MergePolicy.MergeSpecification spec;
+
+ MergeObserver(MergePolicy.MergeSpecification spec) {
+ this.spec = spec;
+ }
+
+ /**
+ * Returns the number of merges in this specification.
+ *
+ * @return number of merges, or 0 if no merges were scheduled
+ */
+ public int numMerges() {
Review Comment:
Excellent suggestion! This is a far better way to provide progress tracking
without exposing mutable `OneMerge` objects. I'll add `numCompletedMerges()`
that iterates through the merges and checks `mergeCompleted.isDone()`.
Users can then track progress as: `100 * numCompletedMerges() / numMerges()`
~~I'll also update `toString()` to show the completion count for better
debugging.~~
--
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]