lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1201381 - in /lucene/dev/branches/lucene2621: ./ dev-tools/idea/lucene/contrib/ lucene/ lucene/contrib/sandbox/src/test/org/apache/lucene/sandbox/queries/regex/ lucene/src/java/org/apache/lucene/index/ lucene/src/java/org/apache/lucene/ind...
Date Sun, 13 Nov 2011 01:02:38 GMT
Author: rmuir
Date: Sun Nov 13 01:02:36 2011
New Revision: 1201381

URL: http://svn.apache.org/viewvc?rev=1201381&view=rev
Log:
LUCENE-2621: merge trunk (1201045:1201380)

Modified:
    lucene/dev/branches/lucene2621/   (props changed)
    lucene/dev/branches/lucene2621/dev-tools/idea/lucene/contrib/   (props changed)
    lucene/dev/branches/lucene2621/lucene/   (props changed)
    lucene/dev/branches/lucene2621/lucene/CHANGES.txt
    lucene/dev/branches/lucene2621/lucene/contrib/sandbox/src/test/org/apache/lucene/sandbox/queries/regex/TestSpanRegexQuery.java   (props changed)
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/TermInfosReaderIndex.java   (props changed)
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/FieldComparator.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TimeLimitingCollector.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/Counter.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
    lucene/dev/branches/lucene2621/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
    lucene/dev/branches/lucene2621/modules/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeFilterBuilder.java   (props changed)
    lucene/dev/branches/lucene2621/solr/   (props changed)
    lucene/dev/branches/lucene2621/solr/CHANGES.txt   (props changed)
    lucene/dev/branches/lucene2621/solr/LICENSE.txt   (props changed)
    lucene/dev/branches/lucene2621/solr/NOTICE.txt   (props changed)
    lucene/dev/branches/lucene2621/solr/README.txt   (props changed)
    lucene/dev/branches/lucene2621/solr/build.xml   (props changed)
    lucene/dev/branches/lucene2621/solr/client/   (props changed)
    lucene/dev/branches/lucene2621/solr/common-build.xml   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/clustering/src/test-files/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler-extras/src/java/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/java/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test-files/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/dataimporthandler/src/test/org/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/uima/src/java/   (props changed)
    lucene/dev/branches/lucene2621/solr/contrib/uima/src/test-files/   (props changed)
    lucene/dev/branches/lucene2621/solr/core/   (props changed)
    lucene/dev/branches/lucene2621/solr/core/src/java/   (props changed)
    lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
    lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java
    lucene/dev/branches/lucene2621/solr/core/src/test/   (props changed)
    lucene/dev/branches/lucene2621/solr/dev-tools/   (props changed)
    lucene/dev/branches/lucene2621/solr/example/   (props changed)
    lucene/dev/branches/lucene2621/solr/lib/   (props changed)
    lucene/dev/branches/lucene2621/solr/scripts/   (props changed)
    lucene/dev/branches/lucene2621/solr/site/   (props changed)
    lucene/dev/branches/lucene2621/solr/site-src/   (props changed)
    lucene/dev/branches/lucene2621/solr/solrj/   (props changed)
    lucene/dev/branches/lucene2621/solr/solrj/src/java/   (props changed)
    lucene/dev/branches/lucene2621/solr/solrj/src/test/org/apache/solr/client/   (props changed)
    lucene/dev/branches/lucene2621/solr/solrj/src/test/org/apache/solr/client/solrj/   (props changed)
    lucene/dev/branches/lucene2621/solr/solrj/src/test/org/apache/solr/common/   (props changed)
    lucene/dev/branches/lucene2621/solr/test-framework/   (props changed)
    lucene/dev/branches/lucene2621/solr/testlogging.properties   (props changed)
    lucene/dev/branches/lucene2621/solr/webapp/   (props changed)

Modified: lucene/dev/branches/lucene2621/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/CHANGES.txt?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene2621/lucene/CHANGES.txt Sun Nov 13 01:02:36 2011
@@ -653,6 +653,14 @@ Changes in backwards compatibility polic
 * LUCENE-3541: Remove IndexInput's protected copyBuf. If you want to
   keep a buffer in your IndexInput, do this yourself in your implementation, 
   and be sure to do the right thing on clone()!  (Robert Muir)
+  
+* LUCENE-2822: TimeLimitingCollector now expects a counter clock instead of
+  relying on a private daemon thread. The global time limiting clock thread
+  has been exposed and is now lazily loaded and fully optional.
+  TimeLimitingCollector now supports setting clock baseline manually to include
+  prelude of a search. Previous versions set the baseline on construction time, 
+  now baseline is set once the first IndexReader is passed to the collector
+  unless set before. (Simon Willnauer)
 
 Changes in runtime behavior
 
@@ -713,6 +721,20 @@ Bug fixes
 * LUCENE-3548: Fix CharsRef#append to extend length of the existing char[]
   and presever existing chars. (Simon Willnauer) 
 
+API Changes
+
+* LUCENE-3454: Rename IndexWriter.optimize to forceMerge to discourage
+  use of this method since it is horribly costly and rarely justified
+  anymore.  MergePolicy.findMergesForOptimize was renamed to
+  findForcedMerges.  IndexReader.isOptimized was
+  deprecated. IndexCommit.isOptimized was replaced with
+  getSegmentCount. (Robert Muir, Mike McCandless)
+
+* LUCENE-3205: Deprecated MultiTermQuery.getTotalNumerOfTerms() [and
+  related methods], as the numbers returned are not useful
+  for multi-segment indexes. They were only needed for tests of
+  NumericRangeQuery.  (Mike McCandless, Uwe Schindler)
+
 New Features
 
 * LUCENE-3448: Added FixedBitSet.and(other/DISI), andNot(other/DISI).

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/LogByteSizeMergePolicy.java Sun Nov 13 01:02:36 2011
@@ -32,12 +32,12 @@ public class LogByteSizeMergePolicy exte
 
   /** Default maximum segment size.  A segment of this size
    *  or larger will never be merged during forceMerge.  @see setMaxMergeMBForForceMerge */
-  public static final double DEFAULT_MAX_MERGE_MB_FOR_MERGE_IF_NEEDED = Long.MAX_VALUE;
+  public static final double DEFAULT_MAX_MERGE_MB_FOR_FORCED_MERGE = Long.MAX_VALUE;
 
   public LogByteSizeMergePolicy() {
     minMergeSize = (long) (DEFAULT_MIN_MERGE_MB*1024*1024);
     maxMergeSize = (long) (DEFAULT_MAX_MERGE_MB*1024*1024);
-    maxMergeSizeForForcedMerge = (long) (DEFAULT_MAX_MERGE_MB_FOR_MERGE_IF_NEEDED*1024*1024);
+    maxMergeSizeForForcedMerge = (long) (DEFAULT_MAX_MERGE_MB_FOR_FORCED_MERGE*1024*1024);
   }
   
   @Override

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java Sun Nov 13 01:02:36 2011
@@ -111,7 +111,6 @@ class ConstantScoreAutoRewrite extends T
       // Strip scores
       final Query result = new ConstantScoreQuery(bq);
       result.setBoost(query.getBoost());
-      query.incTotalNumberOfTerms(size);
       return result;
     }
   }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/FieldComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/FieldComparator.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/FieldComparator.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/FieldComparator.java Sun Nov 13 01:02:36 2011
@@ -258,6 +258,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public FieldComparator setNextReader(AtomicReaderContext context) throws IOException {
+      // NOTE: must do this before calling super otherwise
+      // we compute the docsWithField Bits twice!
       currentReaderValues = FieldCache.DEFAULT.getBytes(context.reader, field, parser, missingValue != null);
       return super.setNextReader(context);
     }
@@ -333,6 +335,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public FieldComparator setNextReader(AtomicReaderContext context) throws IOException {
+      // NOTE: must do this before calling super otherwise
+      // we compute the docsWithField Bits twice!
       currentReaderValues = FieldCache.DEFAULT.getDoubles(context.reader, field, parser, missingValue != null);
       return super.setNextReader(context);
     }
@@ -472,6 +476,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public FieldComparator setNextReader(AtomicReaderContext context) throws IOException {
+      // NOTE: must do this before calling super otherwise
+      // we compute the docsWithField Bits twice!
       currentReaderValues = FieldCache.DEFAULT.getFloats(context.reader, field, parser, missingValue != null);
       return super.setNextReader(context);
     }
@@ -532,6 +538,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public FieldComparator setNextReader(AtomicReaderContext context) throws IOException {
+      // NOTE: must do this before calling super otherwise
+      // we compute the docsWithField Bits twice!
       currentReaderValues = FieldCache.DEFAULT.getShorts(context.reader, field, parser, missingValue != null);
       return super.setNextReader(context);
     }
@@ -614,6 +622,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public FieldComparator setNextReader(AtomicReaderContext context) throws IOException {
+      // NOTE: must do this before calling super otherwise
+      // we compute the docsWithField Bits twice!
       currentReaderValues = FieldCache.DEFAULT.getInts(context.reader, field, parser, missingValue != null);
       return super.setNextReader(context);
     }
@@ -758,6 +768,8 @@ public abstract class FieldComparator<T>
 
     @Override
     public FieldComparator setNextReader(AtomicReaderContext context) throws IOException {
+      // NOTE: must do this before calling super otherwise
+      // we compute the docsWithField Bits twice!
       currentReaderValues = FieldCache.DEFAULT.getLongs(context.reader, field, parser, missingValue != null);
       return super.setNextReader(context);
     }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java Sun Nov 13 01:02:36 2011
@@ -64,7 +64,6 @@ import org.apache.lucene.util.TermContex
 public abstract class MultiTermQuery extends Query {
   protected final String field;
   protected RewriteMethod rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
-  transient int numberOfTerms = 0;
 
   /** Abstract class that defines how the query is rewritten. */
   public static abstract class RewriteMethod {
@@ -271,38 +270,6 @@ public abstract class MultiTermQuery ext
   }
 
   /**
-   * Expert: Return the number of unique terms visited during execution of the query.
-   * If there are many of them, you may consider using another query type
-   * or reduce your total term count in index.
-   * <p>This method is not thread safe, be sure to only call it when no query is running!
-   * If you re-use the same query instance for another
-   * search, be sure to first reset the term counter
-   * with {@link #clearTotalNumberOfTerms}.
-   * <p>On single-segment indexes / no MultiReaders, you get the correct number of
-   * unique terms for the whole index. Use this number to compare different queries.
-   * For multi-segment indexes this number can also be achieved in
-   * non-constant-score mode. In constant-score mode you get the total number of
-   * terms seeked for all segments / sub-readers.
-   * @see #clearTotalNumberOfTerms
-   */
-  public int getTotalNumberOfTerms() {
-    return numberOfTerms;
-  }
-  
-  /**
-   * Expert: Resets the counting of unique terms.
-   * Do this before executing the query/filter.
-   * @see #getTotalNumberOfTerms
-   */
-  public void clearTotalNumberOfTerms() {
-    numberOfTerms = 0;
-  }
-  
-  protected void incTotalNumberOfTerms(int inc) {
-    numberOfTerms += inc;
-  }
-
-  /**
    * To rewrite to a simpler form, instead return a simpler
    * enum from {@link #getTermsEnum(Terms, AttributeSource)}.  For example,
    * to rewrite to a single term, return a {@link SingleTermsEnum}

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java Sun Nov 13 01:02:36 2011
@@ -78,29 +78,6 @@ public class MultiTermQueryWrapperFilter
   public final String getField() { return query.getField(); }
   
   /**
-   * Expert: Return the number of unique terms visited during execution of the filter.
-   * If there are many of them, you may consider using another filter type
-   * or optimize your total term count in index.
-   * <p>This method is not thread safe, be sure to only call it when no filter is running!
-   * If you re-use the same filter instance for another
-   * search, be sure to first reset the term counter
-   * with {@link #clearTotalNumberOfTerms}.
-   * @see #clearTotalNumberOfTerms
-   */
-  public int getTotalNumberOfTerms() {
-    return query.getTotalNumberOfTerms();
-  }
-  
-  /**
-   * Expert: Resets the counting of unique terms.
-   * Do this before executing the filter.
-   * @see #getTotalNumberOfTerms
-   */
-  public void clearTotalNumberOfTerms() {
-    query.clearTotalNumberOfTerms();
-  }
-  
-  /**
    * Returns a DocIdSet with documents that should be permitted in search
    * results.
    */
@@ -146,7 +123,6 @@ public class MultiTermQueryWrapperFilter
       } while (termsEnum.next() != null);
       // System.out.println("  done termCount=" + termCount);
 
-      query.incTotalNumberOfTerms(termCount);
       return bitSet;
     } else {
       return DocIdSet.EMPTY_DOCIDSET;

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java Sun Nov 13 01:02:36 2011
@@ -125,7 +125,6 @@ public abstract class ScoringRewrite<Q e
         addClause(result, term, termStates[pos].docFreq(), query.getBoost() * boost[pos], termStates[pos]);
       }
     }
-    query.incTotalNumberOfTerms(size);
     return result;
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TimeLimitingCollector.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TimeLimitingCollector.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TimeLimitingCollector.java Sun Nov 13 01:02:36 2011
@@ -20,6 +20,7 @@ package org.apache.lucene.search;
 import java.io.IOException;
 
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.util.Counter;
 import org.apache.lucene.util.ThreadInterruptedException;
 
 /**
@@ -30,69 +31,9 @@ import org.apache.lucene.util.ThreadInte
  */
 public class TimeLimitingCollector extends Collector {
 
-  /** 
-   * Default timer resolution.
-   * @see #setResolution(long) 
-   */
-  public static final int DEFAULT_RESOLUTION = 20;
-
-  /**
-   * Default for {@link #isGreedy()}.
-   * @see #isGreedy()
-   */
-  public boolean DEFAULT_GREEDY = false; 
-
-  private static long resolution = DEFAULT_RESOLUTION;
-  
-  private boolean greedy = DEFAULT_GREEDY ;
-
-  private static final class TimerThread extends Thread  {
-
-    // NOTE: we can avoid explicit synchronization here for several reasons:
-    // * updates to volatile long variables are atomic
-    // * only single thread modifies this value
-    // * use of volatile keyword ensures that it does not reside in
-    //   a register, but in main memory (so that changes are visible to
-    //   other threads).
-    // * visibility of changes does not need to be instantaneous, we can
-    //   afford losing a tick or two.
-    //
-    // See section 17 of the Java Language Specification for details.
-    private volatile long time = 0;
-
-    /**
-     * TimerThread provides a pseudo-clock service to all searching
-     * threads, so that they can count elapsed time with less overhead
-     * than repeatedly calling System.currentTimeMillis.  A single
-     * thread should be created to be used for all searches.
-     */
-    private TimerThread() {
-      super("TimeLimitedCollector timer thread");
-      this.setDaemon( true );
-    }
-
-    @Override
-    public void run() {
-      while (true) {
-        // TODO: Use System.nanoTime() when Lucene moves to Java SE 5.
-        time += resolution;
-        try {
-          Thread.sleep( resolution );
-        } catch (InterruptedException ie) {
-          throw new ThreadInterruptedException(ie);
-        }
-      }
-    }
-
-    /**
-     * Get the timer value in milliseconds.
-     */
-    public long getMilliseconds() {
-      return time;
-    }
-  }
 
   /** Thrown when elapsed search time exceeds allowed search time. */
+  @SuppressWarnings("serial")
   public static class TimeExceededException extends RuntimeException {
     private long timeAllowed;
     private long timeElapsed;
@@ -117,58 +58,59 @@ public class TimeLimitingCollector exten
     }
   }
 
-  // Declare and initialize a single static timer thread to be used by
-  // all TimeLimitedCollector instances.  The JVM assures that
-  // this only happens once.
-  private final static TimerThread TIMER_THREAD = new TimerThread();
-  
-  static  {
-    TIMER_THREAD.start();
-  }
-
-  private final long t0;
-  private final long timeout;
+  private long t0 = Long.MIN_VALUE;
+  private long timeout = Long.MIN_VALUE;
   private final Collector collector;
-  
+  private final Counter clock;
+  private final long ticksAllowed;
+  private boolean greedy = false;
   private int docBase;
 
   /**
    * Create a TimeLimitedCollector wrapper over another {@link Collector} with a specified timeout.
    * @param collector the wrapped {@link Collector}
-   * @param timeAllowed max time allowed for collecting hits after which {@link TimeExceededException} is thrown
+   * @param clock the timer clock
+   * @param ticksAllowed max time allowed for collecting
+   * hits after which {@link TimeExceededException} is thrown
    */
-  public TimeLimitingCollector(final Collector collector, final long timeAllowed ) {
+  public TimeLimitingCollector(final Collector collector, Counter clock, final long ticksAllowed ) {
     this.collector = collector;
-    t0 = TIMER_THREAD.getMilliseconds();
-    this.timeout = t0 + timeAllowed;
+    this.clock = clock;
+    this.ticksAllowed = ticksAllowed;
   }
-
-  /** 
-   * Return the timer resolution.
-   * @see #setResolution(long)
-   */
-  public static long getResolution() {
-    return resolution;
+  
+  /**
+   * Sets the baseline for this collector. By default the collectors baseline is 
+   * initialized once the first reader is passed to the collector. 
+   * To include operations executed in prior to the actual document collection
+   * set the baseline through this method in your prelude.
+   * <p>
+   * Example usage:
+   * <pre>
+   *   Counter clock = ...;
+   *   long baseline = clock.get();
+   *   // ... prepare search
+   *   TimeLimitingCollector collector = new TimeLimitingCollector(c, clock, numTicks);
+   *   collector.setBaseline(baseline);
+   *   indexSearcher.search(query, collector);
+   * </pre>
+   * </p>
+   * @see #setBaseline() 
+   * @param clockTime
+   */
+  public void setBaseline(long clockTime) {
+    t0 = clockTime;
+    timeout = t0 + ticksAllowed;
   }
-
+  
   /**
-   * Set the timer resolution.
-   * The default timer resolution is 20 milliseconds. 
-   * This means that a search required to take no longer than 
-   * 800 milliseconds may be stopped after 780 to 820 milliseconds.
-   * <br>Note that: 
-   * <ul>
-   * <li>Finer (smaller) resolution is more accurate but less efficient.</li>
-   * <li>Setting resolution to less than 5 milliseconds will be silently modified to 5 milliseconds.</li>
-   * <li>Setting resolution smaller than current resolution might take effect only after current 
-   * resolution. (Assume current resolution of 20 milliseconds is modified to 5 milliseconds, 
-   * then it can take up to 20 milliseconds for the change to have effect.</li>
-   * </ul>      
+   * Syntactic sugar for {@link #setBaseline(long)} using {@link Counter#get()}
+   * on the clock passed to the construcutor.
    */
-  public static void setResolution(long newResolution) {
-    resolution = Math.max(newResolution,5); // 5 milliseconds is about the minimum reasonable time for a Object.wait(long) call.
+  public void setBaseline() {
+    setBaseline(clock.get());
   }
-
+  
   /**
    * Checks if this time limited collector is greedy in collecting the last hit.
    * A non greedy collector, upon a timeout, would throw a {@link TimeExceededException} 
@@ -199,7 +141,7 @@ public class TimeLimitingCollector exten
    */
   @Override
   public void collect(final int doc) throws IOException {
-    long time = TIMER_THREAD.getMilliseconds();
+    final long time = clock.get();
     if (timeout < time) {
       if (greedy) {
         //System.out.println(this+"  greedy: before failing, collecting doc: "+(docBase + doc)+"  "+(time-t0));
@@ -216,6 +158,9 @@ public class TimeLimitingCollector exten
   public void setNextReader(AtomicReaderContext context) throws IOException {
     collector.setNextReader(context);
     this.docBase = context.docBase;
+    if (Long.MIN_VALUE == t0) {
+      setBaseline();
+    }
   }
   
   @Override
@@ -228,4 +173,131 @@ public class TimeLimitingCollector exten
     return collector.acceptsDocsOutOfOrder();
   }
 
+
+  /**
+   * Returns the global TimerThreads {@link Counter}
+   * <p>
+   * Invoking this creates may create a new instance of {@link TimerThread} iff
+   * the global {@link TimerThread} has never been accessed before. The thread
+   * returned from this method is started on creation and will be alive unless
+   * you stop the {@link TimerThread} via {@link TimerThread#stopTimer()}.
+   * </p>
+   * @return the global TimerThreads {@link Counter}
+   * @lucene.experimental
+   */
+  public static Counter getGlobalCounter() {
+    return TimerThreadHolder.THREAD.counter;
+  }
+  
+  /**
+   * Returns the global {@link TimerThread}.
+   * <p>
+   * Invoking this creates may create a new instance of {@link TimerThread} iff
+   * the global {@link TimerThread} has never been accessed before. The thread
+   * returned from this method is started on creation and will be alive unless
+   * you stop the {@link TimerThread} via {@link TimerThread#stopTimer()}.
+   * </p>
+   * 
+   * @return the global {@link TimerThread}
+   * @lucene.experimental
+   */
+  public static TimerThread getGlobalTimerThread() {
+    return TimerThreadHolder.THREAD;
+  }
+  
+  private static final class TimerThreadHolder {
+    static final TimerThread THREAD;
+    static {
+      THREAD = new TimerThread(Counter.newCounter(true));
+      THREAD.start();
+    }
+  }
+
+  /**
+   * @lucene.experimental
+   */
+  public static final class TimerThread extends Thread  {
+    
+    public static final String THREAD_NAME = "TimeLimitedCollector timer thread";
+    public static final int DEFAULT_RESOLUTION = 20;
+    // NOTE: we can avoid explicit synchronization here for several reasons:
+    // * updates to volatile long variables are atomic
+    // * only single thread modifies this value
+    // * use of volatile keyword ensures that it does not reside in
+    //   a register, but in main memory (so that changes are visible to
+    //   other threads).
+    // * visibility of changes does not need to be instantaneous, we can
+    //   afford losing a tick or two.
+    //
+    // See section 17 of the Java Language Specification for details.
+    private volatile long time = 0;
+    private volatile boolean stop = false;
+    private volatile long resolution;
+    final Counter counter;
+    
+    public TimerThread(long resolution, Counter counter) {
+      super(THREAD_NAME);
+      this.resolution = resolution;
+      this.counter = counter;
+      this.setDaemon(true);
+    }
+    
+    public TimerThread(Counter counter) {
+      this(DEFAULT_RESOLUTION, counter);
+    }
+
+    @Override
+    public void run() {
+      while (!stop) {
+        // TODO: Use System.nanoTime() when Lucene moves to Java SE 5.
+        counter.addAndGet(resolution);
+        try {
+          Thread.sleep( resolution );
+        } catch (InterruptedException ie) {
+          throw new ThreadInterruptedException(ie);
+        }
+      }
+    }
+
+    /**
+     * Get the timer value in milliseconds.
+     */
+    public long getMilliseconds() {
+      return time;
+    }
+    
+    /**
+     * Stops the timer thread 
+     */
+    public void stopTimer() {
+      stop = true;
+    }
+    
+    /** 
+     * Return the timer resolution.
+     * @see #setResolution(long)
+     */
+    public long getResolution() {
+      return resolution;
+    }
+    
+    /**
+     * Set the timer resolution.
+     * The default timer resolution is 20 milliseconds. 
+     * This means that a search required to take no longer than 
+     * 800 milliseconds may be stopped after 780 to 820 milliseconds.
+     * <br>Note that: 
+     * <ul>
+     * <li>Finer (smaller) resolution is more accurate but less efficient.</li>
+     * <li>Setting resolution to less than 5 milliseconds will be silently modified to 5 milliseconds.</li>
+     * <li>Setting resolution smaller than current resolution might take effect only after current 
+     * resolution. (Assume current resolution of 20 milliseconds is modified to 5 milliseconds, 
+     * then it can take up to 20 milliseconds for the change to have effect.</li>
+     * </ul>      
+     */
+    public void setResolution(long resolution) {
+      this.resolution = Math.max(resolution, 5); // 5 milliseconds is about the minimum reasonable time for a Object.wait(long) call.
+    }
+  }
+  
 }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java Sun Nov 13 01:02:36 2011
@@ -163,7 +163,6 @@ public abstract class TopTermsRewrite<Q 
       assert reader.docFreq(term) == st.termState.docFreq() : "reader DF is " + reader.docFreq(term) + " vs " + st.termState.docFreq() + " term=" + term;
       addClause(q, term, st.termState.docFreq(), query.getBoost() * st.boost, st.termState); // add to query
     }
-    query.incTotalNumberOfTerms(scoreTerms.length);
     return q;
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/Counter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/Counter.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/Counter.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/Counter.java Sun Nov 13 01:02:36 2011
@@ -77,7 +77,7 @@ public abstract class Counter {
   }
 
   private final static class AtomicCounter extends Counter {
-    private AtomicLong count;
+    private final AtomicLong count = new AtomicLong();
 
     @Override
     public long addAndGet(long delta) {

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Sun Nov 13 01:02:36 2011
@@ -93,7 +93,7 @@ public class TestIndexReader extends Luc
       IndexReader r3 = IndexReader.openIfChanged(r2);
       assertNotNull(r3);
       assertFalse(c.equals(r3.getIndexCommit()));
-      assertFalse(r2.getIndexCommit().getSegmentCount() == 1);
+      assertFalse(r2.getIndexCommit().getSegmentCount() == 1 && !r2.hasDeletions());
       r3.close();
 
       writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java Sun Nov 13 01:02:36 2011
@@ -83,29 +83,6 @@ public final class FieldCacheRewriteMeth
     public final String getField() { return query.getField(); }
     
     /**
-     * Expert: Return the number of unique terms visited during execution of the filter.
-     * If there are many of them, you may consider using another filter type
-     * or reduce your total term count in index.
-     * <p>This method is not thread safe, be sure to only call it when no filter is running!
-     * If you re-use the same filter instance for another
-     * search, be sure to first reset the term counter
-     * with {@link #clearTotalNumberOfTerms}.
-     * @see #clearTotalNumberOfTerms
-     */
-    public int getTotalNumberOfTerms() {
-      return query.getTotalNumberOfTerms();
-    }
-    
-    /**
-     * Expert: Resets the counting of unique terms.
-     * Do this before executing the filter.
-     * @see #getTotalNumberOfTerms
-     */
-    public void clearTotalNumberOfTerms() {
-      query.clearTotalNumberOfTerms();
-    }
-    
-    /**
      * Returns a DocIdSet with documents that should be permitted in search
      * results.
      */
@@ -158,8 +135,6 @@ public final class FieldCacheRewriteMeth
             termCount++;
           }
         } while (termsEnum.next() != null);
-        
-        query.incTotalNumberOfTerms(termCount);
       } else {
         return DocIdSet.EMPTY_DOCIDSET;
       }

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java Sun Nov 13 01:02:36 2011
@@ -39,7 +39,7 @@ import org.junit.Test;
 
 public class TestNumericRangeQuery32 extends LuceneTestCase {
   // distance of entries
-  private static final int distance = 6666;
+  private static int distance;
   // shift the starting of the values to the left, to also have negative values:
   private static final int startOffset = - 1 << 15;
   // number of docs to generate for testing
@@ -52,6 +52,7 @@ public class TestNumericRangeQuery32 ext
   @BeforeClass
   public static void beforeClass() throws Exception {
     noDocs = atLeast(4096);
+    distance = (1 << 30) / noDocs;
     directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
         newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
@@ -118,35 +119,27 @@ public class TestNumericRangeQuery32 ext
     int lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
     NumericRangeQuery<Integer> q = NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true);
     NumericRangeFilter<Integer> f = NumericRangeFilter.newIntRange(field, precisionStep, lower, upper, true, true);
-    int lastTerms = 0;
     for (byte i=0; i<3; i++) {
       TopDocs topDocs;
-      int terms;
       String type;
-      q.clearTotalNumberOfTerms();
-      f.clearTotalNumberOfTerms();
       switch (i) {
         case 0:
           type = " (constant score filter rewrite)";
           q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-          terms = q.getTotalNumberOfTerms();
           break;
         case 1:
           type = " (constant score boolean rewrite)";
           q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-          terms = q.getTotalNumberOfTerms();
           break;
         case 2:
           type = " (filter)";
           topDocs = searcher.search(new MatchAllDocsQuery(), f, noDocs, Sort.INDEXORDER);
-          terms = f.getTotalNumberOfTerms();
           break;
         default:
           return;
       }
-      if (VERBOSE) System.out.println("Found "+terms+" distinct terms in range for field '"+field+"'"+type+".");
       ScoreDoc[] sd = topDocs.scoreDocs;
       assertNotNull(sd);
       assertEquals("Score doc count"+type, count, sd.length );
@@ -154,12 +147,6 @@ public class TestNumericRangeQuery32 ext
       assertEquals("First doc"+type, 2*distance+startOffset, Integer.parseInt(doc.get(field)) );
       doc=searcher.doc(sd[sd.length-1].doc);
       assertEquals("Last doc"+type, (1+count)*distance+startOffset, Integer.parseInt(doc.get(field)) );
-      if (i>0 && 
-          (searcher.getIndexReader().getSequentialSubReaders() == null || 
-           searcher.getIndexReader().getSequentialSubReaders().length == 1)) {
-        assertEquals("Distinct term number is equal for all query types", lastTerms, terms);
-      }
-      lastTerms = terms;
     }
   }
 
@@ -180,7 +167,7 @@ public class TestNumericRangeQuery32 ext
   
   @Test
   public void testInverseRange() throws Exception {
-    AtomicReaderContext context = (AtomicReaderContext) new SlowMultiReaderWrapper(searcher.getIndexReader()).getTopReaderContext();
+    AtomicReaderContext context = (AtomicReaderContext) new SlowMultiReaderWrapper(reader).getTopReaderContext();
     NumericRangeFilter<Integer> f = NumericRangeFilter.newIntRange("field8", 8, 1000, -1000, true, true);
     assertSame("A inverse range should return the EMPTY_DOCIDSET instance", DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(context, context.reader.getLiveDocs()));
     f = NumericRangeFilter.newIntRange("field8", 8, Integer.MAX_VALUE, null, false, false);
@@ -207,7 +194,6 @@ public class TestNumericRangeQuery32 ext
     int upper=(count-1)*distance + (distance/3) + startOffset;
     NumericRangeQuery<Integer> q=NumericRangeQuery.newIntRange(field, precisionStep, null, upper, true, true);
     TopDocs topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-    if (VERBOSE) System.out.println("Found "+q.getTotalNumberOfTerms()+" distinct terms in left open range for field '"+field+"'.");
     ScoreDoc[] sd = topDocs.scoreDocs;
     assertNotNull(sd);
     assertEquals("Score doc count", count, sd.length );
@@ -248,7 +234,6 @@ public class TestNumericRangeQuery32 ext
     int lower=(count-1)*distance + (distance/3) +startOffset;
     NumericRangeQuery<Integer> q=NumericRangeQuery.newIntRange(field, precisionStep, lower, null, true, true);
     TopDocs topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-    if (VERBOSE) System.out.println("Found "+q.getTotalNumberOfTerms()+" distinct terms in right open range for field '"+field+"'.");
     ScoreDoc[] sd = topDocs.scoreDocs;
     assertNotNull(sd);
     assertEquals("Score doc count", noDocs-count, sd.length );
@@ -335,7 +320,7 @@ public class TestNumericRangeQuery32 ext
   
   private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
     String field="field"+precisionStep;
-    int termCountT=0,termCountC=0;
+    int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
     int num = _TestUtil.nextInt(random, 10, 20);
     for (int i = 0; i < num; i++) {
       int lower=(int)(random.nextDouble()*noDocs*distance)+startOffset;
@@ -353,45 +338,89 @@ public class TestNumericRangeQuery32 ext
       TopDocs tTopDocs = searcher.search(tq, 1);
       TopDocs cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
       // test exclusive range
       tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, false);
       cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
       // test left exclusive range
       tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, true);
       cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
       // test right exclusive range
       tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, false);
       cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
     }
-    if (precisionStep == Integer.MAX_VALUE && 
-        (searcher.getIndexReader().getSequentialSubReaders() == null || 
-         searcher.getIndexReader().getSequentialSubReaders().length == 1)) {
-      assertEquals("Total number of terms should be equal for unlimited precStep", termCountT, termCountC);
-    } else if (VERBOSE) {
+    
+    checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
+    if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
       System.out.println("Average number of terms during random search on '" + field + "':");
-      System.out.println(" Trie query: " + (((double)termCountT)/(num * 4)));
-      System.out.println(" Classical query: " + (((double)termCountC)/(num * 4)));
+      System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
+      System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
     }
   }
   
   @Test
+  public void testEmptyEnums() throws Exception {
+    int count=3000;
+    int lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
+    // test empty enum
+    assert lower < upper;
+    assertTrue(0 < countTerms(NumericRangeQuery.newIntRange("field4", 4, lower, upper, true, true)));
+    assertEquals(0, countTerms(NumericRangeQuery.newIntRange("field4", 4, upper, lower, true, true)));
+    // test empty enum outside of bounds
+    lower = distance*noDocs+startOffset;
+    upper = 2 * lower;
+    assert lower < upper;
+    assertEquals(0, countTerms(NumericRangeQuery.newIntRange("field4", 4, lower, upper, true, true)));
+  }
+  
+  private int countTerms(MultiTermQuery q) throws Exception {
+    final Terms terms = MultiFields.getTerms(reader, q.getField());
+    if (terms == null)
+      return 0;
+    final TermsEnum termEnum = q.getTermsEnum(terms);
+    assertNotNull(termEnum);
+    int count = 0;
+    BytesRef cur, last = null;
+    while ((cur = termEnum.next()) != null) {
+      count++;
+      if (last != null) {
+        assertTrue(last.compareTo(cur) < 0);
+      }
+      last = new BytesRef(cur);
+    } 
+    assertNull(termEnum.next());
+    return count;
+  }
+  
+  private void checkTermCounts(int precisionStep, int termCountT, int termCountC) {
+    if (precisionStep == Integer.MAX_VALUE) {
+      assertEquals("Number of terms should be equal for unlimited precStep", termCountC, termCountT);
+    } else {
+      assertTrue("Number of terms for NRQ should be <= compared to classical TRQ", termCountT <= termCountC);
+    }
+  }
+
+  @Test
   public void testRandomTrieAndClassicRangeQuery_8bit() throws Exception {
     testRandomTrieAndClassicRangeQuery(8);
   }
@@ -566,40 +595,4 @@ public class TestNumericRangeQuery32 ext
     assertFalse(q2.equals(q1));
   }
   
-  private void testEnum(int lower, int upper) throws Exception {
-    NumericRangeQuery<Integer> q = NumericRangeQuery.newIntRange("field4", 4,
-        lower, upper, true, true);
-    Terms terms = MultiFields.getTerms(searcher.getIndexReader(), "field4");
-    TermsEnum termEnum = q.getTermsEnum(terms);
-    int count = 0;
-    while (termEnum.next() != null) {
-      final BytesRef t = termEnum.term();
-      if (t != null) {
-        final int val = NumericUtils.prefixCodedToInt(t);
-        assertTrue("value not in bounds " + val + " >= " + lower + " && "
-            + val + " <= " + upper, val >= lower && val <= upper);
-        count++;
-      } else
-        break;
-    } 
-    assertNull(termEnum.next());
-    if (VERBOSE) System.out.println("TermEnum on 'field4' for range [" + lower + "," + upper
-        + "] contained " + count + " terms.");
-
-  }
-  
-  @Test
-  public void testEnum() throws Exception {
-    int count=3000;
-    int lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
-    // test enum with values
-    testEnum(lower, upper);
-    // test empty enum
-    testEnum(upper, lower);
-    // test empty enum outside of bounds
-    lower = distance*noDocs+startOffset;
-    upper = 2 * lower;
-    testEnum(lower, upper);
-  }
-  
 }

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java Sun Nov 13 01:02:36 2011
@@ -22,8 +22,11 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.NumericField;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.SlowMultiReaderWrapper;
+import org.apache.lucene.index.Terms;
+import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
@@ -36,7 +39,7 @@ import org.junit.Test;
 
 public class TestNumericRangeQuery64 extends LuceneTestCase {
   // distance of entries
-  private static final long distance = 66666L;
+  private static long distance;
   // shift the starting of the values to the left, to also have negative values:
   private static final long startOffset = - 1L << 31;
   // number of docs to generate for testing
@@ -49,6 +52,7 @@ public class TestNumericRangeQuery64 ext
   @BeforeClass
   public static void beforeClass() throws Exception {
     noDocs = atLeast(4096);
+    distance = (1L << 60) / noDocs;
     directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
         newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
@@ -118,35 +122,27 @@ public class TestNumericRangeQuery64 ext
     long lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
     NumericRangeQuery<Long> q = NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
     NumericRangeFilter<Long> f = NumericRangeFilter.newLongRange(field, precisionStep, lower, upper, true, true);
-    int lastTerms = 0;
     for (byte i=0; i<3; i++) {
       TopDocs topDocs;
-      int terms;
       String type;
-      q.clearTotalNumberOfTerms();
-      f.clearTotalNumberOfTerms();
       switch (i) {
         case 0:
           type = " (constant score filter rewrite)";
           q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-          terms = q.getTotalNumberOfTerms();
           break;
         case 1:
           type = " (constant score boolean rewrite)";
           q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-          terms = q.getTotalNumberOfTerms();
           break;
         case 2:
           type = " (filter)";
           topDocs = searcher.search(new MatchAllDocsQuery(), f, noDocs, Sort.INDEXORDER);
-          terms = f.getTotalNumberOfTerms();
           break;
         default:
           return;
       }
-      if (VERBOSE) System.out.println("Found "+terms+" distinct terms in range for field '"+field+"'"+type+".");
       ScoreDoc[] sd = topDocs.scoreDocs;
       assertNotNull(sd);
       assertEquals("Score doc count"+type, count, sd.length );
@@ -154,12 +150,6 @@ public class TestNumericRangeQuery64 ext
       assertEquals("First doc"+type, 2*distance+startOffset, Long.parseLong(doc.get(field)) );
       doc=searcher.doc(sd[sd.length-1].doc);
       assertEquals("Last doc"+type, (1+count)*distance+startOffset, Long.parseLong(doc.get(field)) );
-      if (i>0 && 
-          (searcher.getIndexReader().getSequentialSubReaders() == null || 
-           searcher.getIndexReader().getSequentialSubReaders().length == 1)) {
-        assertEquals("Distinct term number is equal for all query types", lastTerms, terms);
-      }
-      lastTerms = terms;
     }
   }
 
@@ -213,7 +203,6 @@ public class TestNumericRangeQuery64 ext
     long upper=(count-1)*distance + (distance/3) + startOffset;
     NumericRangeQuery<Long> q=NumericRangeQuery.newLongRange(field, precisionStep, null, upper, true, true);
     TopDocs topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-    if (VERBOSE) System.out.println("Found "+q.getTotalNumberOfTerms()+" distinct terms in left open range for field '"+field+"'.");
     ScoreDoc[] sd = topDocs.scoreDocs;
     assertNotNull(sd);
     assertEquals("Score doc count", count, sd.length );
@@ -259,7 +248,6 @@ public class TestNumericRangeQuery64 ext
     long lower=(count-1)*distance + (distance/3) +startOffset;
     NumericRangeQuery<Long> q=NumericRangeQuery.newLongRange(field, precisionStep, lower, null, true, true);
     TopDocs topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
-    if (VERBOSE) System.out.println("Found "+q.getTotalNumberOfTerms()+" distinct terms in right open range for field '"+field+"'.");
     ScoreDoc[] sd = topDocs.scoreDocs;
     assertNotNull(sd);
     assertEquals("Score doc count", noDocs-count, sd.length );
@@ -352,7 +340,7 @@ public class TestNumericRangeQuery64 ext
   
   private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
     String field="field"+precisionStep;
-    int termCountT=0,termCountC=0;
+    int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
     int num = _TestUtil.nextInt(random, 10, 20);
     for (int i = 0; i < num; i++) {
       long lower=(long)(random.nextDouble()*noDocs*distance)+startOffset;
@@ -370,45 +358,89 @@ public class TestNumericRangeQuery64 ext
       TopDocs tTopDocs = searcher.search(tq, 1);
       TopDocs cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
       // test exclusive range
       tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, false);
       cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
       // test left exclusive range
       tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, true);
       cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
       // test right exclusive range
       tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, false);
       cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
-      termCountT += tq.getTotalNumberOfTerms();
-      termCountC += cq.getTotalNumberOfTerms();
+      totalTermCountT += termCountT = countTerms(tq);
+      totalTermCountC += termCountC = countTerms(cq);
+      checkTermCounts(precisionStep, termCountT, termCountC);
     }
-    if (precisionStep == Integer.MAX_VALUE && 
-        (searcher.getIndexReader().getSequentialSubReaders() == null || 
-         searcher.getIndexReader().getSequentialSubReaders().length == 1)) {
-      assertEquals("Total number of terms should be equal for unlimited precStep", termCountT, termCountC);
-    } else if (VERBOSE) {
+    
+    checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
+    if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
       System.out.println("Average number of terms during random search on '" + field + "':");
-      System.out.println(" Trie query: " + (((double)termCountT)/(num * 4)));
-      System.out.println(" Classical query: " + (((double)termCountC)/(num * 4)));
+      System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
+      System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
     }
   }
   
   @Test
+  public void testEmptyEnums() throws Exception {
+    int count=3000;
+    long lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
+    // test empty enum
+    assert lower < upper;
+    assertTrue(0 < countTerms(NumericRangeQuery.newLongRange("field4", 4, lower, upper, true, true)));
+    assertEquals(0, countTerms(NumericRangeQuery.newLongRange("field4", 4, upper, lower, true, true)));
+    // test empty enum outside of bounds
+    lower = distance*noDocs+startOffset;
+    upper = 2L * lower;
+    assert lower < upper;
+    assertEquals(0, countTerms(NumericRangeQuery.newLongRange("field4", 4, lower, upper, true, true)));
+  }
+  
+  private int countTerms(MultiTermQuery q) throws Exception {
+    final Terms terms = MultiFields.getTerms(reader, q.getField());
+    if (terms == null)
+      return 0;
+    final TermsEnum termEnum = q.getTermsEnum(terms);
+    assertNotNull(termEnum);
+    int count = 0;
+    BytesRef cur, last = null;
+    while ((cur = termEnum.next()) != null) {
+      count++;
+      if (last != null) {
+        assertTrue(last.compareTo(cur) < 0);
+      }
+      last = new BytesRef(cur);
+    } 
+    assertNull(termEnum.next());
+    return count;
+  }
+  
+  private void checkTermCounts(int precisionStep, int termCountT, int termCountC) {
+    if (precisionStep == Integer.MAX_VALUE) {
+      assertEquals("Number of terms should be equal for unlimited precStep", termCountC, termCountT);
+    } else {
+      assertTrue("Number of terms for NRQ should be <= compared to classical TRQ", termCountT <= termCountC);
+    }
+  }
+
+  @Test
   public void testRandomTrieAndClassicRangeQuery_8bit() throws Exception {
     testRandomTrieAndClassicRangeQuery(8);
   }

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java Sun Nov 13 01:02:36 2011
@@ -28,17 +28,17 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.TimeLimitingCollector.TimeExceededException;
+import org.apache.lucene.search.TimeLimitingCollector.TimerThread;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.Counter;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.ThreadInterruptedException;
-import org.junit.Ignore;
 
 /**
  * Tests the {@link TimeLimitingCollector}.  This test checks (1) search
  * correctness (regardless of timeout), (2) expected timeout behavior,
  * and (3) a sanity test with multiple searching threads.
  */
-@Ignore("broken: see https://issues.apache.org/jira/browse/LUCENE-2822")
 public class TestTimeLimitingCollector extends LuceneTestCase {
   private static final int SLOW_DOWN = 3;
   private static final long TIME_ALLOWED = 17 * SLOW_DOWN; // so searches can find about 17 docs.
@@ -57,6 +57,8 @@ public class TestTimeLimitingCollector e
 
   private final String FIELD_NAME = "body";
   private Query query;
+  private Counter counter;
+  private TimerThread counterThread;
 
   /**
    * initializes searcher with a document set
@@ -64,6 +66,9 @@ public class TestTimeLimitingCollector e
   @Override
   public void setUp() throws Exception {
     super.setUp();
+    counter = Counter.newCounter(true);
+    counterThread = new TimerThread(counter);
+    counterThread.start();
     final String docText[] = {
         "docThatNeverMatchesSoWeCanRequireLastDocCollectedToBeGreaterThanZero",
         "one blah three",
@@ -98,7 +103,6 @@ public class TestTimeLimitingCollector e
     
     // warm the searcher
     searcher.search(query, null, 1000);
-
   }
 
   @Override
@@ -106,6 +110,8 @@ public class TestTimeLimitingCollector e
     searcher.close();
     reader.close();
     directory.close();
+    counterThread.stopTimer();
+    counterThread.join();
     super.tearDown();
   }
 
@@ -147,7 +153,7 @@ public class TestTimeLimitingCollector e
   }
 
   private Collector createTimedCollector(MyHitCollector hc, long timeAllowed, boolean greedy) {
-    TimeLimitingCollector res = new TimeLimitingCollector(hc, timeAllowed);
+    TimeLimitingCollector res = new TimeLimitingCollector(hc, counter, timeAllowed);
     res.setGreedy(greedy); // set to true to make sure at least one doc is collected.
     return res;
   }
@@ -199,8 +205,8 @@ public class TestTimeLimitingCollector e
     // verify that elapsed time at exception is within valid limits
     assertEquals( timoutException.getTimeAllowed(), TIME_ALLOWED);
     // a) Not too early
-    assertTrue ( "elapsed="+timoutException.getTimeElapsed()+" <= (allowed-resolution)="+(TIME_ALLOWED-TimeLimitingCollector.getResolution()),
-        timoutException.getTimeElapsed() > TIME_ALLOWED-TimeLimitingCollector.getResolution());
+    assertTrue ( "elapsed="+timoutException.getTimeElapsed()+" <= (allowed-resolution)="+(TIME_ALLOWED-counterThread.getResolution()),
+        timoutException.getTimeElapsed() > TIME_ALLOWED-counterThread.getResolution());
     // b) Not too late.
     //    This part is problematic in a busy test system, so we just print a warning.
     //    We already verified that a timeout occurred, we just can't be picky about how long it took.
@@ -215,7 +221,7 @@ public class TestTimeLimitingCollector e
   }
 
   private long maxTime(boolean multiThreaded) {
-    long res = 2 * TimeLimitingCollector.getResolution() + TIME_ALLOWED + SLOW_DOWN; // some slack for less noise in this test
+    long res = 2 * counterThread.getResolution() + TIME_ALLOWED + SLOW_DOWN; // some slack for less noise in this test
     if (multiThreaded) {
       res *= MULTI_THREAD_SLACK; // larger slack  
     }
@@ -226,7 +232,7 @@ public class TestTimeLimitingCollector e
     String s =
       "( " +
       "2*resolution +  TIME_ALLOWED + SLOW_DOWN = " +
-      "2*" + TimeLimitingCollector.getResolution() + " + " + TIME_ALLOWED + " + " + SLOW_DOWN +
+      "2*" + counterThread.getResolution() + " + " + TIME_ALLOWED + " + " + SLOW_DOWN +
       ")";
     if (multiThreaded) {
       s = MULTI_THREAD_SLACK + " * "+s;  
@@ -240,22 +246,22 @@ public class TestTimeLimitingCollector e
   public void testModifyResolution() {
     try {
       // increase and test
-      long resolution = 20 * TimeLimitingCollector.DEFAULT_RESOLUTION; //400
-      TimeLimitingCollector.setResolution(resolution);
-      assertEquals(resolution, TimeLimitingCollector.getResolution());
+      long resolution = 20 * TimerThread.DEFAULT_RESOLUTION; //400
+      counterThread.setResolution(resolution);
+      assertEquals(resolution, counterThread.getResolution());
       doTestTimeout(false,true);
       // decrease much and test
       resolution = 5;
-      TimeLimitingCollector.setResolution(resolution);
-      assertEquals(resolution, TimeLimitingCollector.getResolution());
+      counterThread.setResolution(resolution);
+      assertEquals(resolution, counterThread.getResolution());
       doTestTimeout(false,true);
       // return to default and test
-      resolution = TimeLimitingCollector.DEFAULT_RESOLUTION;
-      TimeLimitingCollector.setResolution(resolution);
-      assertEquals(resolution, TimeLimitingCollector.getResolution());
+      resolution = TimerThread.DEFAULT_RESOLUTION;
+      counterThread.setResolution(resolution);
+      assertEquals(resolution, counterThread.getResolution());
       doTestTimeout(false,true);
     } finally {
-      TimeLimitingCollector.setResolution(TimeLimitingCollector.DEFAULT_RESOLUTION);
+      counterThread.setResolution(TimerThread.DEFAULT_RESOLUTION);
     }
   }
   

Modified: lucene/dev/branches/lucene2621/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java (original)
+++ lucene/dev/branches/lucene2621/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java Sun Nov 13 01:02:36 2011
@@ -136,9 +136,6 @@ public abstract class ReadTask extends P
 
         final String printHitsField = getRunData().getConfig().get("print.hits.field", null);
         if (hits != null && printHitsField != null && printHitsField.length() > 0) {
-          if (q instanceof MultiTermQuery) {
-            System.out.println("MultiTermQuery term count = " + ((MultiTermQuery) q).getTotalNumberOfTerms());
-          }
           System.out.println("totalHits = " + hits.totalHits);
           System.out.println("maxDoc()  = " + reader.maxDoc());
           System.out.println("numDocs() = " + reader.numDocs());

Modified: lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java Sun Nov 13 01:02:36 2011
@@ -1294,7 +1294,7 @@ public class SolrIndexSearcher extends I
       }
       
       if( timeAllowed > 0 ) {
-        collector = new TimeLimitingCollector(collector, timeAllowed);
+        collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), timeAllowed);
       }
       if (pf.postFilter != null) {
         pf.postFilter.setLastDelegate(collector);
@@ -1323,7 +1323,7 @@ public class SolrIndexSearcher extends I
       }
       Collector collector = topCollector;
       if( timeAllowed > 0 ) {
-        collector = new TimeLimitingCollector(collector, timeAllowed);
+        collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), timeAllowed);
       }
       if (pf.postFilter != null) {
         pf.postFilter.setLastDelegate(collector);
@@ -1413,7 +1413,7 @@ public class SolrIndexSearcher extends I
        }
 
        if( timeAllowed > 0 ) {
-         collector = new TimeLimitingCollector(collector, timeAllowed);
+         collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), timeAllowed);
        }
       if (pf.postFilter != null) {
         pf.postFilter.setLastDelegate(collector);
@@ -1449,7 +1449,7 @@ public class SolrIndexSearcher extends I
       Collector collector = setCollector;
 
       if( timeAllowed > 0 ) {
-        collector = new TimeLimitingCollector(collector, timeAllowed );
+        collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), timeAllowed );
       }
       if (pf.postFilter != null) {
         pf.postFilter.setLastDelegate(collector);

Modified: lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java?rev=1201381&r1=1201380&r2=1201381&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java (original)
+++ lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java Sun Nov 13 01:02:36 2011
@@ -31,7 +31,7 @@ public class CommitUpdateCommand extends
   /**
    * During optimize, optimize down to <= this many segments.  Must be >= 1
    *
-   * @see org.apache.lucene.index.IndexWriter#optimize(int)
+   * @see org.apache.lucene.index.IndexWriter#forceMerge(int)
    */
   public int maxOptimizeSegments = 1;
 



Mime
View raw message