mirror of https://github.com/apache/lucene.git
Refactor dummy scorables. (#14046)
This makes our scores that produce dummy scorables share the same implementation.
This commit is contained in:
parent
e34e0824fd
commit
a833887be6
|
@ -39,7 +39,7 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer {
|
||||||
private final DocIdSetIterator[] iterators;
|
private final DocIdSetIterator[] iterators;
|
||||||
private final DocIdSetIterator lead1, lead2;
|
private final DocIdSetIterator lead1, lead2;
|
||||||
private final Scorable scorer1, scorer2;
|
private final Scorable scorer1, scorer2;
|
||||||
private final DocAndScore scorable = new DocAndScore();
|
private final SimpleScorable scorable = new SimpleScorable();
|
||||||
private final double[] sumOfOtherClauses;
|
private final double[] sumOfOtherClauses;
|
||||||
private final int maxDoc;
|
private final int maxDoc;
|
||||||
|
|
||||||
|
@ -202,20 +202,4 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer {
|
||||||
public long cost() {
|
public long cost() {
|
||||||
return lead1.cost();
|
return lead1.cost();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DocAndScore extends Scorable {
|
|
||||||
|
|
||||||
float score;
|
|
||||||
float minCompetitiveScore;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float score() throws IOException {
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMinCompetitiveScore(float minScore) throws IOException {
|
|
||||||
this.minCompetitiveScore = minScore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ final class BooleanScorer extends BulkScorer {
|
||||||
final DisiWrapper[] leads;
|
final DisiWrapper[] leads;
|
||||||
final HeadPriorityQueue head;
|
final HeadPriorityQueue head;
|
||||||
final TailPriorityQueue tail;
|
final TailPriorityQueue tail;
|
||||||
final Score score = new Score();
|
final SimpleScorable score = new SimpleScorable();
|
||||||
final int minShouldMatch;
|
final int minShouldMatch;
|
||||||
final long cost;
|
final long cost;
|
||||||
final boolean needsScores;
|
final boolean needsScores;
|
||||||
|
|
|
@ -251,7 +251,7 @@ final class BooleanScorerSupplier extends ScorerSupplier {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final LeafCollector noScoreCollector =
|
final LeafCollector noScoreCollector =
|
||||||
new LeafCollector() {
|
new LeafCollector() {
|
||||||
Score fake = new Score();
|
SimpleScorable fake = new SimpleScorable();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setScorer(Scorable scorer) throws IOException {
|
public void setScorer(Scorable scorer) throws IOException {
|
||||||
|
|
|
@ -53,7 +53,7 @@ public final class MatchAllDocsQuery extends Query {
|
||||||
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
|
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
max = Math.min(max, maxDoc);
|
max = Math.min(max, maxDoc);
|
||||||
Score scorer = new Score();
|
SimpleScorable scorer = new SimpleScorable();
|
||||||
scorer.score = score;
|
scorer.score = score;
|
||||||
collector.setScorer(scorer);
|
collector.setScorer(scorer);
|
||||||
for (int doc = min; doc < max; ++doc) {
|
for (int doc = min; doc < max; ++doc) {
|
||||||
|
|
|
@ -43,8 +43,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
// The minimum value of minCompetitiveScore that would produce a more favorable partitioning.
|
// The minimum value of minCompetitiveScore that would produce a more favorable partitioning.
|
||||||
float nextMinCompetitiveScore;
|
float nextMinCompetitiveScore;
|
||||||
private final long cost;
|
private final long cost;
|
||||||
float minCompetitiveScore;
|
final SimpleScorable scorable = new SimpleScorable();
|
||||||
private final Score scorable = new Score();
|
|
||||||
final double[] maxScoreSums;
|
final double[] maxScoreSums;
|
||||||
private final DisiWrapper filter;
|
private final DisiWrapper filter;
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
while (top.doc < outerWindowMax) {
|
while (top.doc < outerWindowMax) {
|
||||||
scoreInnerWindow(collector, acceptDocs, outerWindowMax, filter);
|
scoreInnerWindow(collector, acceptDocs, outerWindowMax, filter);
|
||||||
top = essentialQueue.top();
|
top = essentialQueue.top();
|
||||||
if (minCompetitiveScore >= nextMinCompetitiveScore) {
|
if (scorable.minCompetitiveScore >= nextMinCompetitiveScore) {
|
||||||
// The minimum competitive score increased substantially, so we can now partition scorers
|
// The minimum competitive score increased substantially, so we can now partition scorers
|
||||||
// in a more favorable way.
|
// in a more favorable way.
|
||||||
break;
|
break;
|
||||||
|
@ -254,7 +253,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
// We specialize handling the second best scorer, which seems to help a bit with performance.
|
// We specialize handling the second best scorer, which seems to help a bit with performance.
|
||||||
// But this is the exact same logic as in the below for loop.
|
// But this is the exact same logic as in the below for loop.
|
||||||
if ((float) MathUtil.sumUpperBound(score + maxScoreSumAtLead2, allScorers.length)
|
if ((float) MathUtil.sumUpperBound(score + maxScoreSumAtLead2, allScorers.length)
|
||||||
< minCompetitiveScore) {
|
< scorable.minCompetitiveScore) {
|
||||||
// a competitive match is not possible according to max scores, skip to the next candidate
|
// a competitive match is not possible according to max scores, skip to the next candidate
|
||||||
lead1.doc = lead1.iterator.nextDoc();
|
lead1.doc = lead1.iterator.nextDoc();
|
||||||
continue;
|
continue;
|
||||||
|
@ -272,7 +271,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
|
|
||||||
for (int i = allScorers.length - 3; i >= firstRequiredScorer; --i) {
|
for (int i = allScorers.length - 3; i >= firstRequiredScorer; --i) {
|
||||||
if ((float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length)
|
if ((float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length)
|
||||||
< minCompetitiveScore) {
|
< scorable.minCompetitiveScore) {
|
||||||
// a competitive match is not possible according to max scores, skip to the next candidate
|
// a competitive match is not possible according to max scores, skip to the next candidate
|
||||||
lead1.doc = lead1.iterator.nextDoc();
|
lead1.doc = lead1.iterator.nextDoc();
|
||||||
continue outer;
|
continue outer;
|
||||||
|
@ -389,7 +388,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
for (int i = numNonEssentialClauses - 1; i >= 0; --i) {
|
for (int i = numNonEssentialClauses - 1; i >= 0; --i) {
|
||||||
float maxPossibleScore =
|
float maxPossibleScore =
|
||||||
(float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length);
|
(float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length);
|
||||||
if (maxPossibleScore < minCompetitiveScore) {
|
if (maxPossibleScore < scorable.minCompetitiveScore) {
|
||||||
// Hit is not competitive.
|
// Hit is not competitive.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -435,7 +434,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
double newMaxScoreSum = maxScoreSum + w.maxWindowScore;
|
double newMaxScoreSum = maxScoreSum + w.maxWindowScore;
|
||||||
float maxScoreSumFloat =
|
float maxScoreSumFloat =
|
||||||
(float) MathUtil.sumUpperBound(newMaxScoreSum, firstEssentialScorer + 1);
|
(float) MathUtil.sumUpperBound(newMaxScoreSum, firstEssentialScorer + 1);
|
||||||
if (maxScoreSumFloat < minCompetitiveScore) {
|
if (maxScoreSumFloat < scorable.minCompetitiveScore) {
|
||||||
maxScoreSum = newMaxScoreSum;
|
maxScoreSum = newMaxScoreSum;
|
||||||
allScorers[firstEssentialScorer] = w;
|
allScorers[firstEssentialScorer] = w;
|
||||||
maxScoreSums[firstEssentialScorer] = maxScoreSum;
|
maxScoreSums[firstEssentialScorer] = maxScoreSum;
|
||||||
|
@ -473,7 +472,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
if (firstRequiredScorer > 1) {
|
if (firstRequiredScorer > 1) {
|
||||||
maxPossibleScoreWithoutPreviousClause += maxScoreSums[firstRequiredScorer - 2];
|
maxPossibleScoreWithoutPreviousClause += maxScoreSums[firstRequiredScorer - 2];
|
||||||
}
|
}
|
||||||
if ((float) maxPossibleScoreWithoutPreviousClause >= minCompetitiveScore) {
|
if ((float) maxPossibleScoreWithoutPreviousClause >= scorable.minCompetitiveScore) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// The sum of maximum scores ignoring the previous clause is less than the minimum
|
// The sum of maximum scores ignoring the previous clause is less than the minimum
|
||||||
|
@ -507,19 +506,4 @@ final class MaxScoreBulkScorer extends BulkScorer {
|
||||||
public long cost() {
|
public long cost() {
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Score extends Scorable {
|
|
||||||
|
|
||||||
float score;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float score() {
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMinCompetitiveScore(float minScore) throws IOException {
|
|
||||||
MaxScoreBulkScorer.this.minCompetitiveScore = minScore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.lucene.search;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by {@link BulkScorer}s that need to pass a {@link Scorable} to {@link
|
|
||||||
* LeafCollector#setScorer}.
|
|
||||||
*/
|
|
||||||
final class Score extends Scorable {
|
|
||||||
float score;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float score() {
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -55,7 +55,7 @@ public class SortRescorer extends Rescorer {
|
||||||
int docBase = 0;
|
int docBase = 0;
|
||||||
|
|
||||||
LeafCollector leafCollector = null;
|
LeafCollector leafCollector = null;
|
||||||
Score score = new Score();
|
SimpleScorable score = new SimpleScorable();
|
||||||
|
|
||||||
while (hitUpto < hits.length) {
|
while (hitUpto < hits.length) {
|
||||||
ScoreDoc hit = hits[hitUpto];
|
ScoreDoc hit = hits[hitUpto];
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class TestBooleanScorer extends LuceneTestCase {
|
||||||
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
|
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
assert min == 0;
|
assert min == 0;
|
||||||
collector.setScorer(new Score());
|
collector.setScorer(new SimpleScorable());
|
||||||
collector.collect(0);
|
collector.collect(0);
|
||||||
return DocIdSetIterator.NO_MORE_DOCS;
|
return DocIdSetIterator.NO_MORE_DOCS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class TestConstantScoreQuery extends LuceneTestCase {
|
||||||
|
|
||||||
// for the combined BQ, the scorer should always be BooleanScorer's BucketScorer, because our
|
// for the combined BQ, the scorer should always be BooleanScorer's BucketScorer, because our
|
||||||
// scorer supports out-of order collection!
|
// scorer supports out-of order collection!
|
||||||
final Class<Score> bucketScorerClass = Score.class;
|
final Class<SimpleScorable> bucketScorerClass = SimpleScorable.class;
|
||||||
checkHits(searcher, csqbq, csqbq.getBoost(), bucketScorerClass);
|
checkHits(searcher, csqbq, csqbq.getBoost(), bucketScorerClass);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.close(reader, directory);
|
IOUtils.close(reader, directory);
|
||||||
|
|
|
@ -658,7 +658,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
|
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
|
||||||
|
|
||||||
// less than the minimum score of every clause
|
// less than the minimum score of every clause
|
||||||
scorer.minCompetitiveScore = 0.09f;
|
scorer.scorable.minCompetitiveScore = 0.09f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -666,7 +666,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
|
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
|
||||||
|
|
||||||
// equal to the maximum score of `the`
|
// equal to the maximum score of `the`
|
||||||
scorer.minCompetitiveScore = 0.1f;
|
scorer.scorable.minCompetitiveScore = 0.1f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -674,7 +674,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
|
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
|
||||||
|
|
||||||
// gt than the minimum score of `the`
|
// gt than the minimum score of `the`
|
||||||
scorer.minCompetitiveScore = 0.11f;
|
scorer.scorable.minCompetitiveScore = 0.11f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -683,7 +683,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(the, scorer.allScorers[0].scorer);
|
assertSame(the, scorer.allScorers[0].scorer);
|
||||||
|
|
||||||
// equal to the sum of the max scores of the and quick
|
// equal to the sum of the max scores of the and quick
|
||||||
scorer.minCompetitiveScore = 1.1f;
|
scorer.scorable.minCompetitiveScore = 1.1f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -692,7 +692,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(the, scorer.allScorers[0].scorer);
|
assertSame(the, scorer.allScorers[0].scorer);
|
||||||
|
|
||||||
// greater than the sum of the max scores of the and quick
|
// greater than the sum of the max scores of the and quick
|
||||||
scorer.minCompetitiveScore = 1.11f;
|
scorer.scorable.minCompetitiveScore = 1.11f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -703,7 +703,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// equal to the sum of the max scores of the and fox
|
// equal to the sum of the max scores of the and fox
|
||||||
scorer.minCompetitiveScore = 1.2f;
|
scorer.scorable.minCompetitiveScore = 1.2f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -714,7 +714,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// greater than the sum of the max scores of the and fox
|
// greater than the sum of the max scores of the and fox
|
||||||
scorer.minCompetitiveScore = 1.21f;
|
scorer.scorable.minCompetitiveScore = 1.21f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -725,7 +725,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// equal to the sum of the max scores of quick and fox
|
// equal to the sum of the max scores of quick and fox
|
||||||
scorer.minCompetitiveScore = 2.1f;
|
scorer.scorable.minCompetitiveScore = 2.1f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -736,7 +736,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// greater than the sum of the max scores of quick and fox
|
// greater than the sum of the max scores of quick and fox
|
||||||
scorer.minCompetitiveScore = 2.11f;
|
scorer.scorable.minCompetitiveScore = 2.11f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -747,7 +747,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// greater than the sum of the max scores of quick and fox
|
// greater than the sum of the max scores of quick and fox
|
||||||
scorer.minCompetitiveScore = 2.11f;
|
scorer.scorable.minCompetitiveScore = 2.11f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -758,7 +758,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// equal to the sum of the max scores of all terms
|
// equal to the sum of the max scores of all terms
|
||||||
scorer.minCompetitiveScore = 2.2f;
|
scorer.scorable.minCompetitiveScore = 2.2f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertTrue(scorer.partitionScorers());
|
assertTrue(scorer.partitionScorers());
|
||||||
|
@ -769,7 +769,7 @@ public class TestMaxScoreBulkScorer extends LuceneTestCase {
|
||||||
assertSame(fox, scorer.allScorers[2].scorer);
|
assertSame(fox, scorer.allScorers[2].scorer);
|
||||||
|
|
||||||
// greater than the sum of the max scores of all terms
|
// greater than the sum of the max scores of all terms
|
||||||
scorer.minCompetitiveScore = 2.21f;
|
scorer.scorable.minCompetitiveScore = 2.21f;
|
||||||
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
|
||||||
scorer.updateMaxWindowScores(4, 100);
|
scorer.updateMaxWindowScores(4, 100);
|
||||||
assertFalse(scorer.partitionScorers()); // no possible match in this window
|
assertFalse(scorer.partitionScorers()); // no possible match in this window
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
collector1 = new TerminateAfterCollector(collector1, 1);
|
collector1 = new TerminateAfterCollector(collector1, 1);
|
||||||
collector2 = new TerminateAfterCollector(collector2, 2);
|
collector2 = new TerminateAfterCollector(collector2, 2);
|
||||||
|
|
||||||
Scorable scorer = new Score();
|
SimpleScorable scorer = new SimpleScorable();
|
||||||
|
|
||||||
List<Collector> collectors = Arrays.asList(collector1, collector2);
|
List<Collector> collectors = Arrays.asList(collector1, collector2);
|
||||||
Collections.shuffle(collectors, random());
|
Collections.shuffle(collectors, random());
|
||||||
|
@ -333,7 +333,7 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
final LeafCollector ac = c.getLeafCollector(null);
|
final LeafCollector ac = c.getLeafCollector(null);
|
||||||
ac.collect(1);
|
ac.collect(1);
|
||||||
c.getLeafCollector(null);
|
c.getLeafCollector(null);
|
||||||
c.getLeafCollector(null).setScorer(new Score());
|
c.getLeafCollector(null).setScorer(new SimpleScorable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -355,7 +355,7 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
LeafCollector ac = c.getLeafCollector(null);
|
LeafCollector ac = c.getLeafCollector(null);
|
||||||
ac.collect(1);
|
ac.collect(1);
|
||||||
ac = c.getLeafCollector(null);
|
ac = c.getLeafCollector(null);
|
||||||
ac.setScorer(new Score());
|
ac.setScorer(new SimpleScorable());
|
||||||
|
|
||||||
for (DummyCollector dc : dcs) {
|
for (DummyCollector dc : dcs) {
|
||||||
assertTrue(dc.collectCalled);
|
assertTrue(dc.collectCalled);
|
||||||
|
@ -407,23 +407,23 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
() -> {
|
() -> {
|
||||||
collector(ScoreMode.COMPLETE_NO_SCORES, ScoreCachingWrappingScorer.class)
|
collector(ScoreMode.COMPLETE_NO_SCORES, ScoreCachingWrappingScorer.class)
|
||||||
.getLeafCollector(ctx)
|
.getLeafCollector(ctx)
|
||||||
.setScorer(new Score());
|
.setScorer(new SimpleScorable());
|
||||||
});
|
});
|
||||||
|
|
||||||
// no collector needs scores => no caching
|
// no collector needs scores => no caching
|
||||||
Collector c1 = collector(ScoreMode.COMPLETE_NO_SCORES, Score.class);
|
Collector c1 = collector(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class);
|
||||||
Collector c2 = collector(ScoreMode.COMPLETE_NO_SCORES, Score.class);
|
Collector c2 = collector(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class);
|
||||||
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score());
|
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable());
|
||||||
|
|
||||||
// only one collector needs scores => no caching
|
// only one collector needs scores => no caching
|
||||||
c1 = collector(ScoreMode.COMPLETE, Score.class);
|
c1 = collector(ScoreMode.COMPLETE, SimpleScorable.class);
|
||||||
c2 = collector(ScoreMode.COMPLETE_NO_SCORES, Score.class);
|
c2 = collector(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class);
|
||||||
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score());
|
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable());
|
||||||
|
|
||||||
// several collectors need scores => caching
|
// several collectors need scores => caching
|
||||||
c1 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
c1 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
||||||
c2 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
c2 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
||||||
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score());
|
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable());
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
|
@ -440,11 +440,11 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
collector(ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class);
|
collector(ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class);
|
||||||
Collector c2 =
|
Collector c2 =
|
||||||
collector(ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class);
|
collector(ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class);
|
||||||
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score());
|
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable());
|
||||||
|
|
||||||
c1 = collector(ScoreMode.TOP_SCORES, ScoreCachingWrappingScorer.class);
|
c1 = collector(ScoreMode.TOP_SCORES, ScoreCachingWrappingScorer.class);
|
||||||
c2 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
c2 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
||||||
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score());
|
MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable());
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
|
@ -498,7 +498,7 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
|
|
||||||
Collector mc = MultiCollector.wrap(c1, c2);
|
Collector mc = MultiCollector.wrap(c1, c2);
|
||||||
LeafCollector lc = mc.getLeafCollector(ctx);
|
LeafCollector lc = mc.getLeafCollector(ctx);
|
||||||
lc.setScorer(new Score());
|
lc.setScorer(new SimpleScorable());
|
||||||
lc.collect(0); // OK
|
lc.collect(0); // OK
|
||||||
assertTrue("c1's collect should be called", c1.collectCalled);
|
assertTrue("c1's collect should be called", c1.collectCalled);
|
||||||
assertTrue("c2's collect should be called", c2.collectCalled);
|
assertTrue("c2's collect should be called", c2.collectCalled);
|
||||||
|
@ -549,21 +549,21 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
LeafCollector lc = mc.getLeafCollector(ctx);
|
LeafCollector lc = mc.getLeafCollector(ctx);
|
||||||
assertFalse(c1.setScorerCalled);
|
assertFalse(c1.setScorerCalled);
|
||||||
assertFalse(c2.setScorerCalled);
|
assertFalse(c2.setScorerCalled);
|
||||||
lc.setScorer(new Score());
|
lc.setScorer(new SimpleScorable());
|
||||||
assertTrue(c1.setScorerCalled);
|
assertTrue(c1.setScorerCalled);
|
||||||
assertTrue(c2.setScorerCalled);
|
assertTrue(c2.setScorerCalled);
|
||||||
c1.setScorerCalled = false;
|
c1.setScorerCalled = false;
|
||||||
c2.setScorerCalled = false;
|
c2.setScorerCalled = false;
|
||||||
lc.collect(0); // OK
|
lc.collect(0); // OK
|
||||||
|
|
||||||
lc.setScorer(new Score());
|
lc.setScorer(new SimpleScorable());
|
||||||
assertTrue(c1.setScorerCalled);
|
assertTrue(c1.setScorerCalled);
|
||||||
assertTrue(c2.setScorerCalled);
|
assertTrue(c2.setScorerCalled);
|
||||||
c1.setScorerCalled = false;
|
c1.setScorerCalled = false;
|
||||||
c2.setScorerCalled = false;
|
c2.setScorerCalled = false;
|
||||||
|
|
||||||
lc.collect(1); // OK, but c1 should terminate
|
lc.collect(1); // OK, but c1 should terminate
|
||||||
lc.setScorer(new Score());
|
lc.setScorer(new SimpleScorable());
|
||||||
assertFalse(c1.setScorerCalled);
|
assertFalse(c1.setScorerCalled);
|
||||||
assertTrue(c2.setScorerCalled);
|
assertTrue(c2.setScorerCalled);
|
||||||
c2.setScorerCalled = false;
|
c2.setScorerCalled = false;
|
||||||
|
@ -573,7 +573,7 @@ public class TestMultiCollector extends LuceneTestCase {
|
||||||
() -> {
|
() -> {
|
||||||
lc.collect(2);
|
lc.collect(2);
|
||||||
});
|
});
|
||||||
lc.setScorer(new Score());
|
lc.setScorer(new SimpleScorable());
|
||||||
assertFalse(c1.setScorerCalled);
|
assertFalse(c1.setScorerCalled);
|
||||||
assertFalse(c2.setScorerCalled);
|
assertFalse(c2.setScorerCalled);
|
||||||
|
|
||||||
|
|
|
@ -89,19 +89,30 @@ public class TestMultiCollectorManager extends LuceneTestCase {
|
||||||
LeafReaderContext ctx = reader.leaves().get(0);
|
LeafReaderContext ctx = reader.leaves().get(0);
|
||||||
|
|
||||||
// no collector needs scores => no caching
|
// no collector needs scores => no caching
|
||||||
CollectorManager<?, ?> cm1 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, Score.class);
|
CollectorManager<?, ?> cm1 =
|
||||||
CollectorManager<?, ?> cm2 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, Score.class);
|
collectorManager(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class);
|
||||||
new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score());
|
CollectorManager<?, ?> cm2 =
|
||||||
|
collectorManager(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class);
|
||||||
|
new MultiCollectorManager(cm1, cm2)
|
||||||
|
.newCollector()
|
||||||
|
.getLeafCollector(ctx)
|
||||||
|
.setScorer(new SimpleScorable());
|
||||||
|
|
||||||
// only one collector needs scores => no caching
|
// only one collector needs scores => no caching
|
||||||
cm1 = collectorManager(ScoreMode.COMPLETE, Score.class);
|
cm1 = collectorManager(ScoreMode.COMPLETE, SimpleScorable.class);
|
||||||
cm2 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, Score.class);
|
cm2 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class);
|
||||||
new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score());
|
new MultiCollectorManager(cm1, cm2)
|
||||||
|
.newCollector()
|
||||||
|
.getLeafCollector(ctx)
|
||||||
|
.setScorer(new SimpleScorable());
|
||||||
|
|
||||||
// several collectors need scores => caching
|
// several collectors need scores => caching
|
||||||
cm1 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
cm1 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
||||||
cm2 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
cm2 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
||||||
new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score());
|
new MultiCollectorManager(cm1, cm2)
|
||||||
|
.newCollector()
|
||||||
|
.getLeafCollector(ctx)
|
||||||
|
.setScorer(new SimpleScorable());
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
|
@ -120,13 +131,19 @@ public class TestMultiCollectorManager extends LuceneTestCase {
|
||||||
CollectorManager<?, ?> cm2 =
|
CollectorManager<?, ?> cm2 =
|
||||||
collectorManager(
|
collectorManager(
|
||||||
ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class);
|
ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class);
|
||||||
new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score());
|
new MultiCollectorManager(cm1, cm2)
|
||||||
|
.newCollector()
|
||||||
|
.getLeafCollector(ctx)
|
||||||
|
.setScorer(new SimpleScorable());
|
||||||
|
|
||||||
// both wrapped collector managers need scores, but one is exhaustive, so they should
|
// both wrapped collector managers need scores, but one is exhaustive, so they should
|
||||||
// see a ScoreCachingWrappingScorer pass in as their scorer:
|
// see a ScoreCachingWrappingScorer pass in as their scorer:
|
||||||
cm1 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
cm1 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class);
|
||||||
cm2 = collectorManager(ScoreMode.TOP_SCORES, ScoreCachingWrappingScorer.class);
|
cm2 = collectorManager(ScoreMode.TOP_SCORES, ScoreCachingWrappingScorer.class);
|
||||||
new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score());
|
new MultiCollectorManager(cm1, cm2)
|
||||||
|
.newCollector()
|
||||||
|
.getLeafCollector(ctx)
|
||||||
|
.setScorer(new SimpleScorable());
|
||||||
|
|
||||||
reader.close();
|
reader.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
|
|
Loading…
Reference in New Issue