Index: lucene/core/src/test/org/apache/lucene/search/TestEarlyTermination.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/search/TestEarlyTermination.java	(révision 0)
+++ lucene/core/src/test/org/apache/lucene/search/TestEarlyTermination.java	(copie de travail)
@@ -0,0 +1,93 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestEarlyTermination extends LuceneTestCase {
+
+  Directory dir;
+  RandomIndexWriter writer;
+
+  public void setUp() throws Exception {
+    super.setUp();
+    dir = newDirectory();
+    writer = new RandomIndexWriter(random(), dir);
+    final int numDocs = atLeast(100);
+    for (int i = 0; i < numDocs; i++) {
+      writer.addDocument(new Document());
+      if (rarely()) {
+        writer.commit();
+      }
+    }
+  }
+
+  public void tearDown() throws Exception {
+    super.tearDown();
+    writer.close();
+    dir.close();
+  }
+
+  public void testEarlyTermination() throws IOException {
+    final int iters = atLeast(5);
+    final IndexReader reader = writer.getReader();
+    final IndexSearcher searcher = new IndexSearcher(reader);
+
+    for (int i = 0; i < iters; ++i) {
+      final Collector collector = new Collector() {
+
+        final boolean outOfOrder = random().nextBoolean();
+        boolean collectionTerminated = true;
+
+        @Override
+        public void setScorer(Scorer scorer) throws IOException {}
+
+        @Override
+        public void collect(int doc) throws IOException {
+          assertFalse(collectionTerminated);
+          if (rarely()) {
+            collectionTerminated = true;
+            throw new CollectionTerminatedException();
+          }
+        }
+
+        @Override
+        public void setNextReader(AtomicReaderContext context) throws IOException {
+          collectionTerminated = false;
+        }
+
+        @Override
+        public boolean acceptsDocsOutOfOrder() {
+          return outOfOrder;
+        }
+
+      };
+
+      searcher.search(new MatchAllDocsQuery(), collector);
+    }
+    reader.close();
+  }
+
+}

Modification de propriétés sur lucene/core/src/test/org/apache/lucene/search/TestEarlyTermination.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java	(révision 1458962)
+++ lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java	(copie de travail)
@@ -32,7 +32,6 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.lucene.document.Document;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.DirectoryReader; // javadocs
 import org.apache.lucene.index.IndexReader;
@@ -595,7 +594,12 @@
       collector.setNextReader(ctx);
       Scorer scorer = weight.scorer(ctx, !collector.acceptsDocsOutOfOrder(), true, ctx.reader().getLiveDocs());
       if (scorer != null) {
-        scorer.score(collector);
+        try {
+          scorer.score(collector);
+        } catch (CollectionTerminatedException e) {
+          // collection was terminated prematurely
+          // continue with the following leaf
+        }
       }
     }
   }
Index: lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java	(révision 0)
+++ lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java	(copie de travail)
@@ -0,0 +1,34 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** Throw this exception in {@link Collector#collect(int)} to prematurely
+ *  terminate collection of the current leaf.
+ *  <p>Note: IndexSearcher swallows this exception and never re-throws it.
+ *  As a consequence, you should not catch it when calling
+ *  {@link IndexSearcher#search} as it is unnecessary and might hide misuse
+ *  of this exception. */
+@SuppressWarnings("serial")
+public final class CollectionTerminatedException extends RuntimeException {
+
+  /** Sole constructor. */
+  public CollectionTerminatedException() {
+    super();
+  }
+
+}

Modification de propriétés sur lucene/core/src/java/org/apache/lucene/search/CollectionTerminatedException.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: lucene/core/src/java/org/apache/lucene/search/Collector.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/search/Collector.java	(révision 1458962)
+++ lucene/core/src/java/org/apache/lucene/search/Collector.java	(copie de travail)
@@ -134,7 +134,10 @@
   /**
    * Called once for every document matching a query, with the unbased document
    * number.
-   * 
+   * <p>Note: The collection of the current segment can be terminated by throwing
+   * a {@link CollectionTerminatedException}. In this case, the last docs of the
+   * current {@link AtomicReaderContext} will be skipped and {@link IndexSearcher}
+   * will swallow the exception and continue collection with the next leaf.
    * <p>
    * Note: This is called in an inner search loop. For good search performance,
    * implementations of this method should not call {@link IndexSearcher#doc(int)} or
