lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1585967 - /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/Weight.java
Date Wed, 09 Apr 2014 13:38:59 GMT
Author: mikemccand
Date: Wed Apr  9 13:38:58 2014
New Revision: 1585967

URL: http://svn.apache.org/r1585967
Log:
LUCENE-5554: break out separate Weight.scoreRange/scoreAll so hotspot is relatively happy
again after LUCENE-5487

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/Weight.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/Weight.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/Weight.java?rev=1585967&r1=1585966&r2=1585967&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/Weight.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/Weight.java Wed Apr  9
13:38:58 2014
@@ -21,7 +21,6 @@ import java.io.IOException;
 
 import org.apache.lucene.index.AtomicReader; // javadocs
 import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.IndexReaderContext; // javadocs
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.Bits;
@@ -145,7 +144,9 @@ public abstract class Weight {
     private final Scorer scorer;
 
     public DefaultBulkScorer(Scorer scorer) {
-      assert scorer != null;
+      if (scorer == null) {
+        throw new NullPointerException();
+      }
       this.scorer = scorer;
     }
 
@@ -158,14 +159,31 @@ public abstract class Weight {
       // Collector doing something "interesting" in
       // setScorer will be forced to use BS2 anyways:
       collector.setScorer(scorer);
-      if (scorer.docID() == -1) {
-        scorer.nextDoc();
+      if (max == DocIdSetIterator.NO_MORE_DOCS) {
+        scoreAll(collector, scorer);
+        return false;
+      } else {
+        int doc = scorer.docID();
+        if (doc < 0) {
+          doc = scorer.nextDoc();
+        }
+        return scoreRange(collector, scorer, doc, max);
+      }
+    }
+    
+    static boolean scoreRange(LeafCollector collector, Scorer scorer, int currentDoc, int
end) throws IOException {
+      while (currentDoc < end) {
+        collector.collect(currentDoc);
+        currentDoc = scorer.nextDoc();
       }
+      return currentDoc != DocIdSetIterator.NO_MORE_DOCS;
+    }
+    
+    static void scoreAll(LeafCollector collector, Scorer scorer) throws IOException {
       int doc;
-      for (doc = scorer.docID(); doc < max; doc = scorer.nextDoc()) {
+      while ((doc = scorer.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
         collector.collect(doc);
       }
-      return doc != DocsEnum.NO_MORE_DOCS;
     }
   }
 



Mime
View raw message