You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2009/03/18 17:44:51 UTC

svn commit: r755639 - in /lucene/java/trunk/src/java/org/apache/lucene/search: BooleanScorer2.java DisjunctionSumScorer.java

Author: mikemccand
Date: Wed Mar 18 16:44:50 2009
New Revision: 755639

URL: http://svn.apache.org/viewvc?rev=755639&view=rev
Log:
LUCENE-1145: small improvements to DisjunctionSumScorer

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/BooleanScorer2.java
    lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionSumScorer.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/BooleanScorer2.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/BooleanScorer2.java?rev=755639&r1=755638&r2=755639&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/BooleanScorer2.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/BooleanScorer2.java Wed Mar 18 16:44:50 2009
@@ -178,7 +178,7 @@
   }
 
   private Scorer countingDisjunctionSumScorer(final List scorers,
-                                              int minNrShouldMatch)
+                                              int minNrShouldMatch) throws IOException
   // each scorer from the list counted as a single matcher
   {
     return new DisjunctionSumScorer(scorers, minNrShouldMatch) {
@@ -286,7 +286,7 @@
    * Uses the given required scorer and the prohibitedScorers.
    * @param requiredCountingSumScorer A required scorer already built.
    */
-  private Scorer addProhibitedScorers(Scorer requiredCountingSumScorer)
+  private Scorer addProhibitedScorers(Scorer requiredCountingSumScorer) throws IOException
   {
     return (prohibitedScorers.size() == 0)
           ? requiredCountingSumScorer // no prohibited

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionSumScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionSumScorer.java?rev=755639&r1=755638&r2=755639&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionSumScorer.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionSumScorer.java Wed Mar 18 16:44:50 2009
@@ -49,8 +49,7 @@
    * <code>nrMatchers</code> is the number of matching scorers,
    * and all scorers are after the matching doc, or are exhausted.
    */
-  private ScorerDocQueue scorerDocQueue = null;
-  private int queueSize = -1; // used to avoid size() method calls on scorerDocQueue
+  private ScorerDocQueue scorerDocQueue;
   
   /** The document number of the current match. */
   private int currentDoc = -1;
@@ -70,7 +69,7 @@
    * <br>When minimumNrMatchers equals the number of subScorers,
    * it more efficient to use <code>ConjunctionScorer</code>.
    */
-  public DisjunctionSumScorer( List subScorers, int minimumNrMatchers) {
+  public DisjunctionSumScorer( List subScorers, int minimumNrMatchers) throws IOException {
     super(null);
     
     nrScorers = subScorers.size();
@@ -84,12 +83,14 @@
 
     this.minimumNrMatchers = minimumNrMatchers;
     this.subScorers = subScorers;
+
+    initScorerDocQueue();
   }
   
   /** Construct a <code>DisjunctionScorer</code>, using one as the minimum number
    * of matching subscorers.
    */
-  public DisjunctionSumScorer(List subScorers) {
+  public DisjunctionSumScorer(List subScorers) throws IOException {
     this(subScorers, 1);
   }
 
@@ -99,13 +100,10 @@
   private void initScorerDocQueue() throws IOException {
     Iterator si = subScorers.iterator();
     scorerDocQueue = new ScorerDocQueue(nrScorers);
-    queueSize = 0;
     while (si.hasNext()) {
       Scorer se = (Scorer) si.next();
       if (se.next()) { // doc() method will be used in scorerDocQueue.
-        if (scorerDocQueue.insert(se)) {
-          queueSize++;
-        }
+        scorerDocQueue.insert(se);
       }
     }
   }
@@ -140,9 +138,6 @@
   }
 
   public boolean next() throws IOException {
-    if (scorerDocQueue == null) {
-      initScorerDocQueue();
-    }
     return (scorerDocQueue.size() >= minimumNrMatchers)
           && advanceAfterCurrent();
   }
@@ -173,7 +168,7 @@
       nrMatchers = 1;
       do { // Until all subscorers are after currentDoc
         if (! scorerDocQueue.topNextAndAdjustElsePop()) {
-          if (--queueSize == 0) {
+          if (scorerDocQueue.size() == 0) {
             break; // nothing more to advance, check for last match.
           }
         }
@@ -186,7 +181,7 @@
       
       if (nrMatchers >= minimumNrMatchers) {
         return true;
-      } else if (queueSize < minimumNrMatchers) {
+      } else if (scorerDocQueue.size() < minimumNrMatchers) {
         return false;
       }
     } while (true);
@@ -214,10 +209,7 @@
    * @return true iff there is such a match.
    */
   public boolean skipTo(int target) throws IOException {
-    if (scorerDocQueue == null) {
-      initScorerDocQueue();
-    }
-    if (queueSize < minimumNrMatchers) {
+    if (scorerDocQueue.size() < minimumNrMatchers) {
       return false;
     }
     if (target <= currentDoc) {
@@ -227,7 +219,7 @@
       if (scorerDocQueue.topDoc() >= target) {
         return advanceAfterCurrent();
       } else if (! scorerDocQueue.topSkipToAndAdjustElsePop(target)) {
-        if (--queueSize < minimumNrMatchers) {
+        if (scorerDocQueue.size() < minimumNrMatchers) {
           return false;
         }
       }