lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1201329 - in /lucene/dev/trunk: lucene/ lucene/src/java/org/apache/lucene/search/ lucene/src/test/org/apache/lucene/search/ modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/
Date Sat, 12 Nov 2011 21:13:20 GMT
Author: uschindler
Date: Sat Nov 12 21:13:20 2011
New Revision: 1201329

URL: http://svn.apache.org/viewvc?rev=1201329&view=rev
Log:
LUCENE-3205: Remove MultiTermQuery get/inc/clear totalNumberOfTerms

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
    lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Sat Nov 12 21:13:20 2011
@@ -730,6 +730,11 @@ API Changes
   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/trunk/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java
(original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ConstantScoreAutoRewrite.java
Sat Nov 12 21:13:20 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/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQuery.java Sat Nov
12 21:13:20 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/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
(original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
Sat Nov 12 21:13:20 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/trunk/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/ScoringRewrite.java Sat Nov
12 21:13:20 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/trunk/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/TopTermsRewrite.java Sat Nov
12 21:13:20 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/trunk/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/FieldCacheRewriteMethod.java
Sat Nov 12 21:13:20 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/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
Sat Nov 12 21:13:20 2011
@@ -118,35 +118,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 +146,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 +166,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 +193,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 +233,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 +319,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,44 +337,73 @@ 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)));
     }
   }
   
+  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 +579,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/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
Sat Nov 12 21:13:20 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;
@@ -118,35 +121,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 +149,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 +202,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 +247,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 +339,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,44 +357,73 @@ 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)));
     }
   }
   
+  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/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java?rev=1201329&r1=1201328&r2=1201329&view=diff
==============================================================================
--- lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
(original)
+++ lucene/dev/trunk/modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
Sat Nov 12 21:13:20 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());



Mime
View raw message