You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/04/29 13:54:11 UTC
svn commit: r1676720 - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/search/
lucene/core/src/test/org/apache/lucene/search/
Author: jpountz
Date: Wed Apr 29 11:54:02 2015
New Revision: 1676720
URL: http://svn.apache.org/r1676720
Log:
LUCENE-6330: BS1 should not decode norms when scores are not needed.
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/lucene/core/ (props changed)
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java
Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1676720&r1=1676719&r2=1676720&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Wed Apr 29 11:54:02 2015
@@ -78,6 +78,9 @@ Optimizations
* LUCENE-6455: Require a minimum index size to enable query caching in order
not to cache eg. on MemoryIndex. (Adrien Grand)
+* LUCENE-6330: BooleanScorer (used for top-level disjunctions) does not decode
+ norms when not necessary anymore. (Adrien Grand)
+
Bug Fixes
* LUCENE-6378: Fix all RuntimeExceptions to throw the underlying root cause.
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java?rev=1676720&r1=1676719&r2=1676720&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java Wed Apr 29 11:54:02 2015
@@ -37,6 +37,35 @@ final class BooleanScorer extends BulkSc
static final int SET_SIZE = 1 << (SHIFT - 6);
static final int SET_MASK = SET_SIZE - 1;
+ private static BulkScorer disableScoring(final BulkScorer scorer) {
+ return new BulkScorer() {
+
+ @Override
+ public int score(final LeafCollector collector, int min, int max) throws IOException {
+ final LeafCollector noScoreCollector = new LeafCollector() {
+ FakeScorer fake = new FakeScorer();
+
+ @Override
+ public void setScorer(Scorer scorer) throws IOException {
+ collector.setScorer(fake);
+ }
+
+ @Override
+ public void collect(int doc) throws IOException {
+ fake.doc = doc;
+ collector.collect(doc);
+ }
+ };
+ return scorer.score(noScoreCollector, min, max);
+ }
+
+ @Override
+ public long cost() {
+ return scorer.cost();
+ }
+ };
+ }
+
static class Bucket {
double score;
int freq;
@@ -146,7 +175,7 @@ final class BooleanScorer extends BulkSc
final OrCollector orCollector = new OrCollector();
- BooleanScorer(BooleanWeight weight, boolean disableCoord, int maxCoord, Collection<BulkScorer> scorers, int minShouldMatch) {
+ BooleanScorer(BooleanWeight weight, boolean disableCoord, int maxCoord, Collection<BulkScorer> scorers, int minShouldMatch, boolean needsScores) {
if (minShouldMatch < 1 || minShouldMatch > scorers.size()) {
throw new IllegalArgumentException("minShouldMatch should be within 1..num_scorers. Got " + minShouldMatch);
}
@@ -158,6 +187,11 @@ final class BooleanScorer extends BulkSc
this.tail = new TailPriorityQueue(minShouldMatch - 1);
this.minShouldMatch = minShouldMatch;
for (BulkScorer scorer : scorers) {
+ if (needsScores == false) {
+ // OrCollector calls score() all the time so we have to explicitly
+ // disable scoring in order to avoid decoding useless norms
+ scorer = disableScoring(scorer);
+ }
final BulkScorerAndDoc evicted = tail.insertWithOverflow(new BulkScorerAndDoc(scorer));
if (evicted != null) {
head.add(evicted);
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java?rev=1676720&r1=1676719&r2=1676720&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java Wed Apr 29 11:54:02 2015
@@ -196,6 +196,7 @@ public class BooleanWeight extends Weigh
for (Weight w : weights) {
BooleanClause c = cIter.next();
BulkScorer subScorer = w.bulkScorer(context, acceptDocs);
+
if (subScorer == null) {
if (c.isRequired()) {
return null;
@@ -221,7 +222,7 @@ public class BooleanWeight extends Weigh
return null;
}
- return new BooleanScorer(this, disableCoord, maxCoord, optional, Math.max(1, query.minNrShouldMatch));
+ return new BooleanScorer(this, disableCoord, maxCoord, optional, Math.max(1, query.minNrShouldMatch), needsScores);
}
@Override
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java?rev=1676720&r1=1676719&r2=1676720&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java Wed Apr 29 11:54:02 2015
@@ -254,7 +254,7 @@ public class TestBooleanOr extends Lucen
scorer(5000, 100000, 9999998, 9999999)
);
Collections.shuffle(optionalScorers, random());
- BooleanScorer scorer = new BooleanScorer(null, true, 0, optionalScorers, 1);
+ BooleanScorer scorer = new BooleanScorer(null, true, 0, optionalScorers, 1, random().nextBoolean());
final List<Integer> matches = new ArrayList<>();
scorer.score(new LeafCollector() {