lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r824870 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/search/ src/test/org/apache/lucene/search/
Date Tue, 13 Oct 2009 18:26:38 GMT
Author: buschmi
Date: Tue Oct 13 18:26:37 2009
New Revision: 824870

URL: http://svn.apache.org/viewvc?rev=824870&view=rev
Log:
LUCENE-944: Remove deprecated methods in boolean query.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=824870&r1=824869&r2=824870&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Oct 13 18:26:37 2009
@@ -65,6 +65,8 @@
 * LUCENE-1977: Remove deprecated Term field and accessors in
   MultiTermQuery. (Uwe Schindler)
 
+* LUCENE-944: Remove deprecated methods in BooleanQuery. (Michael Busch)
+
 Bug fixes
 
 * LUCENE-1951: When the text provided to WildcardQuery has no wildcard

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java?rev=824870&r1=824869&r2=824870&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java Tue Oct 13 18:26:37
2009
@@ -310,7 +310,6 @@
       }
       
       // Check if we can return a BooleanScorer
-      scoreDocsInOrder |= !allowDocsOutOfOrder; // until it is removed, factor in the static
setting.
       if (!scoreDocsInOrder && topScorer && required.size() == 0 &&
prohibited.size() < 32) {
         return new BooleanScorer(similarity, minNrShouldMatch, optional, prohibited);
       }
@@ -350,68 +349,6 @@
     
   }
 
-  /**
-   * Whether hit docs may be collected out of docid order.
-   * 
-   * @deprecated this will not be needed anymore, as
-   *             {@link Weight#scoresDocsOutOfOrder()} is used.
-   */
-  private static boolean allowDocsOutOfOrder = true;
-
-  /**
-   * Expert: Indicates whether hit docs may be collected out of docid order.
-   * 
-   * <p>
-   * Background: although the contract of the Scorer class requires that
-   * documents be iterated in order of doc id, this was not true in early
-   * versions of Lucene. Many pieces of functionality in the current Lucene code
-   * base have undefined behavior if this contract is not upheld, but in some
-   * specific simple cases may be faster. (For example: disjunction queries with
-   * less than 32 prohibited clauses; This setting has no effect for other
-   * queries.)
-   * </p>
-   * 
-   * <p>
-   * Specifics: By setting this option to true, docid N might be scored for a
-   * single segment before docid N-1. Across multiple segments, docs may be
-   * scored out of order regardless of this setting - it only applies to scoring
-   * a single segment.
-   * 
-   * Being static, this setting is system wide.
-   * </p>
-   * 
-   * @deprecated this is not needed anymore, as
-   *             {@link Weight#scoresDocsOutOfOrder()} is used.
-   */
-  public static void setAllowDocsOutOfOrder(boolean allow) {
-    allowDocsOutOfOrder = allow;
-  }
-
-  /**
-   * Whether hit docs may be collected out of docid order.
-   * 
-   * @see #setAllowDocsOutOfOrder(boolean)
-   * @deprecated this is not needed anymore, as
-   *             {@link Weight#scoresDocsOutOfOrder()} is used.
-   */
-  public static boolean getAllowDocsOutOfOrder() {
-    return allowDocsOutOfOrder;
-  }  
-  
-  /**
-   * @deprecated Use {@link #setAllowDocsOutOfOrder(boolean)} instead. 
-   */
-  public static void setUseScorer14(boolean use14) {
-	setAllowDocsOutOfOrder(use14);
-  }
-  
-  /**
-   * @deprecated Use {@link #getAllowDocsOutOfOrder()} instead.
-   */
-  public static boolean getUseScorer14() {
-	return getAllowDocsOutOfOrder();
-  }
-
   public Weight createWeight(Searcher searcher) throws IOException {
     return new BooleanWeight(searcher);
   }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java?rev=824870&r1=824869&r2=824870&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java Tue Oct 13 18:26:37
2009
@@ -257,7 +257,7 @@
   public static void checkSkipTo(final Query q, final IndexSearcher s) throws IOException
{
     //System.out.println("Checking "+q);
     
-    if (BooleanQuery.getAllowDocsOutOfOrder()) return;  // in this case order of skipTo()
might differ from that of next().
+    if (q.weight(s).scoresDocsOutOfOrder()) return;  // in this case order of skipTo() might
differ from that of next().
 
     final int skip_op = 0;
     final int next_op = 1;
@@ -277,46 +277,46 @@
         // System.out.print(order[i]==skip_op ? " skip()":" next()");
         // System.out.println();
         final int opidx[] = { 0 };
-
-        final Weight w = q.weight(s);
-        final Scorer scorer = w.scorer(s.getIndexReader(), true, false);
-        if (scorer == null) {
-          continue;
-        }
+        final int lastDoc[] = {-1};
 
         // FUTURE: ensure scorer.doc()==-1
 
-        final int[] sdoc = new int[] { -1 };
         final float maxDiff = 1e-5f;
         s.search(q, new Collector() {
-          private int base = 0;
           private Scorer sc;
+          private IndexReader reader;
+          private Scorer scorer;
 
           public void setScorer(Scorer scorer) throws IOException {
             this.sc = scorer;
           }
 
           public void collect(int doc) throws IOException {
-            doc = doc + base;
             float score = sc.score();
+            lastDoc[0] = doc;
             try {
+              if (scorer == null) {
+                Weight w = q.weight(s);
+                scorer = w.scorer(reader, true, false);
+              }
+              
               int op = order[(opidx[0]++) % order.length];
               // System.out.println(op==skip_op ?
               // "skip("+(sdoc[0]+1)+")":"next()");
-              boolean more = op == skip_op ? scorer.advance(sdoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS
+              boolean more = op == skip_op ? scorer.advance(scorer.docID() + 1) != DocIdSetIterator.NO_MORE_DOCS
                   : scorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS;
-              sdoc[0] = scorer.docID();
+              int scorerDoc = scorer.docID();
               float scorerScore = scorer.score();
               float scorerScore2 = scorer.score();
               float scoreDiff = Math.abs(score - scorerScore);
               float scorerDiff = Math.abs(scorerScore2 - scorerScore);
-              if (!more || doc != sdoc[0] || scoreDiff > maxDiff
+              if (!more || doc != scorerDoc || scoreDiff > maxDiff
                   || scorerDiff > maxDiff) {
                 StringBuilder sbord = new StringBuilder();
                 for (int i = 0; i < order.length; i++)
                   sbord.append(order[i] == skip_op ? " skip()" : " next()");
                 throw new RuntimeException("ERROR matching docs:" + "\n\t"
-                    + (doc != sdoc[0] ? "--> " : "") + "doc=" + sdoc[0]
+                    + (doc != scorerDoc ? "--> " : "") + "doc=" + doc + ", scorerDoc="
+ scorerDoc
                     + "\n\t" + (!more ? "--> " : "") + "tscorer.more=" + more
                     + "\n\t" + (scoreDiff > maxDiff ? "--> " : "")
                     + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff
@@ -335,7 +335,9 @@
           }
 
           public void setNextReader(IndexReader reader, int docBase) {
-            base = docBase;
+            this.reader = reader;
+            this.scorer = null;
+            lastDoc[0] = -1;
           }
 
           public boolean acceptsDocsOutOfOrder() {
@@ -343,12 +345,21 @@
           }
         });
 
-        // make sure next call to scorer is false.
-        int op = order[(opidx[0]++) % order.length];
-        // System.out.println(op==skip_op ? "last: skip()":"last: next()");
-        boolean more = (op == skip_op ? scorer.advance(sdoc[0] + 1) : scorer
-            .nextDoc()) != DocIdSetIterator.NO_MORE_DOCS;
-        Assert.assertFalse(more);
+        List<IndexReader> readerList = new ArrayList<IndexReader>();
+        ReaderUtil.gatherSubReaders(readerList, s.getIndexReader());
+        IndexReader[] readers = (IndexReader[]) readerList.toArray(new IndexReader[0]);
+        for(int i = 0; i < readers.length; i++) {
+          IndexReader reader = readers[i];
+          Weight w = q.weight(s);
+          Scorer scorer = w.scorer(reader, true, false);
+          
+          if (scorer != null) {
+            boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;
+      
+            if (more && lastDoc[0] != -1) 
+              Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+")
got to "+scorer.docID(),more);
+          }
+        }
       }
   }
     
@@ -391,7 +402,7 @@
       }
     });
     
-    List readerList = new ArrayList();
+    List<IndexReader> readerList = new ArrayList<IndexReader>();
     ReaderUtil.gatherSubReaders(readerList, s.getIndexReader());
     IndexReader[] readers = (IndexReader[]) readerList.toArray(new IndexReader[0]);
     for(int i = 0; i < readers.length; i++) {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java?rev=824870&r1=824869&r2=824870&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java Tue Oct 13 18:26:37
2009
@@ -66,19 +66,18 @@
   public void queriesTest(String queryText, int[] expDocNrs) throws Exception {
 //System.out.println();
 //System.out.println("Query: " + queryText);
-    try {
-      Query query1 = makeQuery(queryText);
-      BooleanQuery.setAllowDocsOutOfOrder(true);
-      ScoreDoc[] hits1 = searcher.search(query1, null, 1000).scoreDocs;
-
-      Query query2 = makeQuery(queryText); // there should be no need to parse again...
-      BooleanQuery.setAllowDocsOutOfOrder(false);
-      ScoreDoc[] hits2 = searcher.search(query2, null, 1000).scoreDocs;
-
-      CheckHits.checkHitsQuery(query2, hits1, hits2, expDocNrs);
-    } finally { // even when a test fails.
-      BooleanQuery.setAllowDocsOutOfOrder(false);
-    }
+
+    Query query1 = makeQuery(queryText);
+    TopScoreDocCollector collector = TopScoreDocCollector.create(1000, false);
+    searcher.search(query1, null, collector);
+    ScoreDoc[] hits1 = collector.topDocs().scoreDocs;
+    
+    Query query2 = makeQuery(queryText); // there should be no need to parse again...
+    collector = TopScoreDocCollector.create(1000, true);
+    searcher.search(query2, null, collector);
+    ScoreDoc[] hits2 = collector.topDocs().scoreDocs; 
+      
+    CheckHits.checkHitsQuery(query2, hits1, hits2, expDocNrs);
   }
 
   public void testQueries01() throws Exception {
@@ -165,14 +164,19 @@
         // match up.
         Sort sort = Sort.INDEXORDER;
 
-        BooleanQuery.setAllowDocsOutOfOrder(false);
-
         QueryUtils.check(q1,searcher);
 
-        ScoreDoc[] hits1 = searcher.search(q1,null, 1000, sort).scoreDocs;
+        TopFieldCollector collector = TopFieldCollector.create(sort, 1000,
+            false, true, true, true);
+
+        searcher.search(q1, null, collector);
+        ScoreDoc[] hits1 = collector.topDocs().scoreDocs;
 
-        BooleanQuery.setAllowDocsOutOfOrder(true);
-        ScoreDoc[] hits2 = searcher.search(q1,null, 1000, sort).scoreDocs;
+        collector = TopFieldCollector.create(sort, 1000,
+            false, true, true, false);
+        
+        searcher.search(q1, null, collector);
+        ScoreDoc[] hits2 = collector.topDocs().scoreDocs;
         tot+=hits2.length;
         CheckHits.checkEqual(q1, hits1, hits2);
       }
@@ -181,8 +185,6 @@
       // For easier debugging
       System.out.println("failed query: " + q1);
       throw e;
-    } finally { // even when a test fails.
-      BooleanQuery.setAllowDocsOutOfOrder(false);
     }
 
     // System.out.println("Total hits:"+tot);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=824870&r1=824869&r2=824870&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Tue Oct 13 18:26:37
2009
@@ -836,11 +836,6 @@
         "OutOfOrderOneComparatorScoringMaxScoreCollector" 
     };
     
-    // Save the original value to set later.
-    boolean origVal = BooleanQuery.getAllowDocsOutOfOrder();
-    
-    BooleanQuery.setAllowDocsOutOfOrder(true);
-    
     BooleanQuery bq = new BooleanQuery();
     // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
     // which delegates to BS if there are no mandatory clauses.
@@ -848,28 +843,20 @@
     // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
     // the clause instead of BQ.
     bq.setMinimumNumberShouldMatch(1);
-    try {
-      for (int i = 0; i < sort.length; i++) {
-        for (int j = 0; j < tfcOptions.length; j++) {
-          TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10,
-              tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);
-
-          assertTrue(tdc.getClass().getName().endsWith("$"+actualTFCClasses[j]));
-          
-          full.search(bq, tdc);
-          
-          TopDocs td = tdc.topDocs();
-          ScoreDoc[] sd = td.scoreDocs;
-          assertEquals(10, sd.length);
-        }
+    for (int i = 0; i < sort.length; i++) {
+      for (int j = 0; j < tfcOptions.length; j++) {
+        TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10,
+            tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);
+
+        assertTrue(tdc.getClass().getName().endsWith("$"+actualTFCClasses[j]));
+        
+        full.search(bq, tdc);
+        
+        TopDocs td = tdc.topDocs();
+        ScoreDoc[] sd = td.scoreDocs;
+        assertEquals(10, sd.length);
       }
-    } finally {
-      // Whatever happens, reset BooleanQuery.allowDocsOutOfOrder to the
-      // original value. Don't set it to false in case the implementation in BQ
-      // will change some day.
-      BooleanQuery.setAllowDocsOutOfOrder(origVal);
     }
-
   }
   
   public void testSortWithScoreAndMaxScoreTrackingNoResults() throws Exception {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java?rev=824870&r1=824869&r2=824870&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java Tue
Oct 13 18:26:37 2009
@@ -50,11 +50,6 @@
         "InOrderTopScoreDocCollector" 
     };
     
-    // Save the original value to set later.
-    boolean origVal = BooleanQuery.getAllowDocsOutOfOrder();
-
-    BooleanQuery.setAllowDocsOutOfOrder(true);
-
     BooleanQuery bq = new BooleanQuery();
     // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
     // which delegates to BS if there are no mandatory clauses.
@@ -62,28 +57,19 @@
     // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
     // the clause instead of BQ.
     bq.setMinimumNumberShouldMatch(1);
-    try {
+    IndexSearcher searcher = new IndexSearcher(dir, true);
+    for (int i = 0; i < inOrder.length; i++) {
+      TopDocsCollector tdc = TopScoreDocCollector.create(3, inOrder[i]);
+      assertEquals("org.apache.lucene.search.TopScoreDocCollector$" + actualTSDCClass[i],
tdc.getClass().getName());
       
-      IndexSearcher searcher = new IndexSearcher(dir, true);
-      for (int i = 0; i < inOrder.length; i++) {
-        TopDocsCollector tdc = TopScoreDocCollector.create(3, inOrder[i]);
-        assertEquals("org.apache.lucene.search.TopScoreDocCollector$" + actualTSDCClass[i],
tdc.getClass().getName());
-        
-        searcher.search(new MatchAllDocsQuery(), tdc);
-        
-        ScoreDoc[] sd = tdc.topDocs().scoreDocs;
-        assertEquals(3, sd.length);
-        for (int j = 0; j < sd.length; j++) {
-          assertEquals("expected doc Id " + j + " found " + sd[j].doc, j, sd[j].doc);
-        }
+      searcher.search(new MatchAllDocsQuery(), tdc);
+      
+      ScoreDoc[] sd = tdc.topDocs().scoreDocs;
+      assertEquals(3, sd.length);
+      for (int j = 0; j < sd.length; j++) {
+        assertEquals("expected doc Id " + j + " found " + sd[j].doc, j, sd[j].doc);
       }
-    } finally {
-      // Whatever happens, reset BooleanQuery.allowDocsOutOfOrder to the
-      // original value. Don't set it to false in case the implementation in BQ
-      // will change some day.
-      BooleanQuery.setAllowDocsOutOfOrder(origVal);
     }
-
   }
   
 }



Mime
View raw message