lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1685507 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/search/TimeLimitingCollector.java core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
Date Mon, 15 Jun 2015 08:19:59 GMT
Author: simonw
Date: Mon Jun 15 08:19:58 2015
New Revision: 1685507

URL: http://svn.apache.org/r1685507
Log:
LUCENE-6559: TimeLimitingCollector should check timeout also when LeafCollector is pulled

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1685507&r1=1685506&r2=1685507&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Mon Jun 15 08:19:58 2015
@@ -161,6 +161,9 @@ Bug Fixes
 * LUCENE-6527: Queries now get a dummy Similarity when scores are not needed
   in order to not load unnecessary information like norms. (Adrien Grand)
 
+* LUCENE-6559: TimeLimitingCollector now also checks for timeout when a new
+  leaf reader is pulled ie. if we move from one segment to another even without
+  collecting a hit. (Simon Willnauer)
 
 ======================= Lucene 5.2.0 =======================
 

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java?rev=1685507&r1=1685506&r2=1685507&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
(original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
Mon Jun 15 08:19:58 2015
@@ -136,6 +136,10 @@ public class TimeLimitingCollector imple
     if (Long.MIN_VALUE == t0) {
       setBaseline();
     }
+    final long time = clock.get();
+    if (time - timeout > 0L) {
+      throw new TimeExceededException(timeout - t0, time - t0, -1);
+    }
     return new FilterLeafCollector(collector.getLeafCollector(context)) {
       
       @Override

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java?rev=1685507&r1=1685506&r2=1685507&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
Mon Jun 15 08:19:58 2015
@@ -152,7 +152,7 @@ public class TestTimeLimitingCollector e
       e.printStackTrace();
       assertTrue("Unexpected exception: "+e, false); //==fail
     }
-    assertEquals( "Wrong number of results!", totalResults, totalTLCResults );
+    assertEquals("Wrong number of results!", totalResults, totalTLCResults);
   }
 
   private Collector createTimedCollector(MyHitCollector hc, long timeAllowed, boolean greedy)
{
@@ -267,6 +267,24 @@ public class TestTimeLimitingCollector e
       counterThread.setResolution(TimerThread.DEFAULT_RESOLUTION);
     }
   }
+
+  public void testNoHits() throws IOException {
+    MyHitCollector myHc = new MyHitCollector();
+    Collector collector = createTimedCollector(myHc, -1, random().nextBoolean());
+    // search
+    TimeExceededException timoutException = null;
+    try {
+      BooleanQuery booleanQuery = new BooleanQuery(); // won't match - we only test if we
check timeout when collectors are pulled
+      booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "one")), BooleanClause.Occur.MUST);
+      booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "blueberry")), BooleanClause.Occur.MUST);
+      searcher.search(booleanQuery, collector);
+    } catch (TimeExceededException x) {
+      timoutException = x;
+    }
+    // must get exception
+    assertNotNull("Timeout expected!", timoutException);
+    assertEquals(-1, myHc.getLastDocCollected());
+  }
   
   /** 
    * Test correctness with multiple searching threads.



Mime
View raw message