From a62e716f21228e84cc0a92434441dd9190f3a1a7 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 10 Dec 2024 16:12:05 +0100 Subject: [PATCH] Revert "Refactor dummy scorables. (#14046)" This reverts commit a833887be67b302f7d4067a48debccbe13b4f454. --- .../search/BlockMaxConjunctionBulkScorer.java | 18 +++++++++- .../apache/lucene/search/BooleanScorer.java | 2 +- .../lucene/search/BooleanScorerSupplier.java | 2 +- .../lucene/search/MatchAllDocsQuery.java | 2 +- .../lucene/search/MaxScoreBulkScorer.java | 30 ++++++++++++---- .../java/org/apache/lucene/search/Score.java | 30 ++++++++++++++++ .../apache/lucene/search/SortRescorer.java | 2 +- .../lucene/search/TestBooleanScorer.java | 2 +- .../lucene/search/TestConstantScoreQuery.java | 2 +- .../lucene/search/TestMaxScoreBulkScorer.java | 24 ++++++------- .../lucene/search/TestMultiCollector.java | 36 +++++++++---------- .../search/TestMultiCollectorManager.java | 35 +++++------------- 12 files changed, 115 insertions(+), 70 deletions(-) create mode 100644 lucene/core/src/java/org/apache/lucene/search/Score.java diff --git a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java index defda1ae5340..3022608233e7 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionBulkScorer.java @@ -39,7 +39,7 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer { private final DocIdSetIterator[] iterators; private final DocIdSetIterator lead1, lead2; private final Scorable scorer1, scorer2; - private final SimpleScorable scorable = new SimpleScorable(); + private final DocAndScore scorable = new DocAndScore(); private final double[] sumOfOtherClauses; private final int maxDoc; @@ -202,4 +202,20 @@ private void scoreWindow( public long 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; + } + } } diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java b/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java index bae5b77bba4d..462396e266ea 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java @@ -80,7 +80,7 @@ public DisiWrapper get(int i) { final DisiWrapper[] leads; final HeadPriorityQueue head; final TailPriorityQueue tail; - final SimpleScorable score = new SimpleScorable(); + final Score score = new Score(); final int minShouldMatch; final long cost; final boolean needsScores; diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java b/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java index 576232bab21e..7732445e8cd4 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java @@ -251,7 +251,7 @@ public int score(final LeafCollector collector, Bits acceptDocs, int min, int ma throws IOException { final LeafCollector noScoreCollector = new LeafCollector() { - SimpleScorable fake = new SimpleScorable(); + Score fake = new Score(); @Override public void setScorer(Scorable scorer) throws IOException { diff --git a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java index 138c7ea2b603..8bed66a7f495 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java @@ -53,7 +53,7 @@ public BulkScorer bulkScorer() throws IOException { public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException { max = Math.min(max, maxDoc); - SimpleScorable scorer = new SimpleScorable(); + Score scorer = new Score(); scorer.score = score; collector.setScorer(scorer); for (int doc = min; doc < max; ++doc) { diff --git a/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java b/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java index d557c1749dfd..93dd1ea91e31 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/MaxScoreBulkScorer.java @@ -43,7 +43,8 @@ final class MaxScoreBulkScorer extends BulkScorer { // The minimum value of minCompetitiveScore that would produce a more favorable partitioning. float nextMinCompetitiveScore; private final long cost; - final SimpleScorable scorable = new SimpleScorable(); + float minCompetitiveScore; + private final Score scorable = new Score(); final double[] maxScoreSums; private final DisiWrapper filter; @@ -126,7 +127,7 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max) thr while (top.doc < outerWindowMax) { scoreInnerWindow(collector, acceptDocs, outerWindowMax, filter); top = essentialQueue.top(); - if (scorable.minCompetitiveScore >= nextMinCompetitiveScore) { + if (minCompetitiveScore >= nextMinCompetitiveScore) { // The minimum competitive score increased substantially, so we can now partition scorers // in a more favorable way. break; @@ -253,7 +254,7 @@ private void scoreInnerWindowAsConjunction(LeafCollector collector, Bits acceptD // 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. if ((float) MathUtil.sumUpperBound(score + maxScoreSumAtLead2, allScorers.length) - < scorable.minCompetitiveScore) { + < minCompetitiveScore) { // a competitive match is not possible according to max scores, skip to the next candidate lead1.doc = lead1.iterator.nextDoc(); continue; @@ -271,7 +272,7 @@ private void scoreInnerWindowAsConjunction(LeafCollector collector, Bits acceptD for (int i = allScorers.length - 3; i >= firstRequiredScorer; --i) { if ((float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length) - < scorable.minCompetitiveScore) { + < minCompetitiveScore) { // a competitive match is not possible according to max scores, skip to the next candidate lead1.doc = lead1.iterator.nextDoc(); continue outer; @@ -388,7 +389,7 @@ private void scoreNonEssentialClauses( for (int i = numNonEssentialClauses - 1; i >= 0; --i) { float maxPossibleScore = (float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length); - if (maxPossibleScore < scorable.minCompetitiveScore) { + if (maxPossibleScore < minCompetitiveScore) { // Hit is not competitive. return; } @@ -434,7 +435,7 @@ boolean partitionScorers() { double newMaxScoreSum = maxScoreSum + w.maxWindowScore; float maxScoreSumFloat = (float) MathUtil.sumUpperBound(newMaxScoreSum, firstEssentialScorer + 1); - if (maxScoreSumFloat < scorable.minCompetitiveScore) { + if (maxScoreSumFloat < minCompetitiveScore) { maxScoreSum = newMaxScoreSum; allScorers[firstEssentialScorer] = w; maxScoreSums[firstEssentialScorer] = maxScoreSum; @@ -472,7 +473,7 @@ boolean partitionScorers() { if (firstRequiredScorer > 1) { maxPossibleScoreWithoutPreviousClause += maxScoreSums[firstRequiredScorer - 2]; } - if ((float) maxPossibleScoreWithoutPreviousClause >= scorable.minCompetitiveScore) { + if ((float) maxPossibleScoreWithoutPreviousClause >= minCompetitiveScore) { break; } // The sum of maximum scores ignoring the previous clause is less than the minimum @@ -506,4 +507,19 @@ private int nextCandidate(int rangeEnd) { public long 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; + } + } } diff --git a/lucene/core/src/java/org/apache/lucene/search/Score.java b/lucene/core/src/java/org/apache/lucene/search/Score.java new file mode 100644 index 000000000000..fdda8e2d76eb --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/search/Score.java @@ -0,0 +1,30 @@ +/* + * 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; + } +} diff --git a/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java b/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java index 5ed8e1a03270..e4a4891c570d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/SortRescorer.java @@ -55,7 +55,7 @@ public TopDocs rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int top int docBase = 0; LeafCollector leafCollector = null; - SimpleScorable score = new SimpleScorable(); + Score score = new Score(); while (hitUpto < hits.length) { ScoreDoc hit = hits[hitUpto]; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java index 6a3f24a38ef0..1258dd8b10e9 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java @@ -102,7 +102,7 @@ public BulkScorer bulkScorer() throws IOException { public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException { assert min == 0; - collector.setScorer(new SimpleScorable()); + collector.setScorer(new Score()); collector.collect(0); return DocIdSetIterator.NO_MORE_DOCS; } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java index 33174c9be3d7..7ca3ee39b396 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java @@ -157,7 +157,7 @@ public void testWrapped2Times() throws Exception { // for the combined BQ, the scorer should always be BooleanScorer's BucketScorer, because our // scorer supports out-of order collection! - final Class bucketScorerClass = SimpleScorable.class; + final Class bucketScorerClass = Score.class; checkHits(searcher, csqbq, csqbq.getBoost(), bucketScorerClass); } finally { IOUtils.close(reader, directory); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java index 7ee46a21a580..2f9fcc2a0fd8 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java @@ -658,7 +658,7 @@ public void testPartition() throws IOException { assertEquals(3, scorer.firstRequiredScorer); // no required clauses // less than the minimum score of every clause - scorer.scorable.minCompetitiveScore = 0.09f; + scorer.minCompetitiveScore = 0.09f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -666,7 +666,7 @@ public void testPartition() throws IOException { assertEquals(3, scorer.firstRequiredScorer); // no required clauses // equal to the maximum score of `the` - scorer.scorable.minCompetitiveScore = 0.1f; + scorer.minCompetitiveScore = 0.1f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -674,7 +674,7 @@ public void testPartition() throws IOException { assertEquals(3, scorer.firstRequiredScorer); // no required clauses // gt than the minimum score of `the` - scorer.scorable.minCompetitiveScore = 0.11f; + scorer.minCompetitiveScore = 0.11f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -683,7 +683,7 @@ public void testPartition() throws IOException { assertSame(the, scorer.allScorers[0].scorer); // equal to the sum of the max scores of the and quick - scorer.scorable.minCompetitiveScore = 1.1f; + scorer.minCompetitiveScore = 1.1f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -692,7 +692,7 @@ public void testPartition() throws IOException { assertSame(the, scorer.allScorers[0].scorer); // greater than the sum of the max scores of the and quick - scorer.scorable.minCompetitiveScore = 1.11f; + scorer.minCompetitiveScore = 1.11f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -703,7 +703,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // equal to the sum of the max scores of the and fox - scorer.scorable.minCompetitiveScore = 1.2f; + scorer.minCompetitiveScore = 1.2f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -714,7 +714,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // greater than the sum of the max scores of the and fox - scorer.scorable.minCompetitiveScore = 1.21f; + scorer.minCompetitiveScore = 1.21f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -725,7 +725,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // equal to the sum of the max scores of quick and fox - scorer.scorable.minCompetitiveScore = 2.1f; + scorer.minCompetitiveScore = 2.1f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -736,7 +736,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // greater than the sum of the max scores of quick and fox - scorer.scorable.minCompetitiveScore = 2.11f; + scorer.minCompetitiveScore = 2.11f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -747,7 +747,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // greater than the sum of the max scores of quick and fox - scorer.scorable.minCompetitiveScore = 2.11f; + scorer.minCompetitiveScore = 2.11f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -758,7 +758,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // equal to the sum of the max scores of all terms - scorer.scorable.minCompetitiveScore = 2.2f; + scorer.minCompetitiveScore = 2.2f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertTrue(scorer.partitionScorers()); @@ -769,7 +769,7 @@ public void testPartition() throws IOException { assertSame(fox, scorer.allScorers[2].scorer); // greater than the sum of the max scores of all terms - scorer.scorable.minCompetitiveScore = 2.21f; + scorer.minCompetitiveScore = 2.21f; Collections.shuffle(Arrays.asList(scorer.allScorers), random()); scorer.updateMaxWindowScores(4, 100); assertFalse(scorer.partitionScorers()); // no possible match in this window diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java index b39dff083792..d27d026f9a6c 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollector.java @@ -147,7 +147,7 @@ public void testSetScorerAfterCollectionTerminated() throws IOException { collector1 = new TerminateAfterCollector(collector1, 1); collector2 = new TerminateAfterCollector(collector2, 2); - SimpleScorable scorer = new SimpleScorable(); + Scorable scorer = new Score(); List collectors = Arrays.asList(collector1, collector2); Collections.shuffle(collectors, random()); @@ -333,7 +333,7 @@ public void testNullCollectors() throws Exception { final LeafCollector ac = c.getLeafCollector(null); ac.collect(1); c.getLeafCollector(null); - c.getLeafCollector(null).setScorer(new SimpleScorable()); + c.getLeafCollector(null).setScorer(new Score()); } @Test @@ -355,7 +355,7 @@ public void testCollector() throws Exception { LeafCollector ac = c.getLeafCollector(null); ac.collect(1); ac = c.getLeafCollector(null); - ac.setScorer(new SimpleScorable()); + ac.setScorer(new Score()); for (DummyCollector dc : dcs) { assertTrue(dc.collectCalled); @@ -407,23 +407,23 @@ public void testCacheScoresIfNecessary() throws IOException { () -> { collector(ScoreMode.COMPLETE_NO_SCORES, ScoreCachingWrappingScorer.class) .getLeafCollector(ctx) - .setScorer(new SimpleScorable()); + .setScorer(new Score()); }); // no collector needs scores => no caching - Collector c1 = collector(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class); - Collector c2 = collector(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class); - MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable()); + Collector c1 = collector(ScoreMode.COMPLETE_NO_SCORES, Score.class); + Collector c2 = collector(ScoreMode.COMPLETE_NO_SCORES, Score.class); + MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score()); // only one collector needs scores => no caching - c1 = collector(ScoreMode.COMPLETE, SimpleScorable.class); - c2 = collector(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class); - MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable()); + c1 = collector(ScoreMode.COMPLETE, Score.class); + c2 = collector(ScoreMode.COMPLETE_NO_SCORES, Score.class); + MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score()); // several collectors need scores => caching c1 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class); c2 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class); - MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable()); + MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score()); reader.close(); dir.close(); @@ -440,11 +440,11 @@ public void testScorerWrappingForTopScores() throws IOException { collector(ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class); Collector c2 = collector(ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class); - MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable()); + MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score()); c1 = collector(ScoreMode.TOP_SCORES, ScoreCachingWrappingScorer.class); c2 = collector(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class); - MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new SimpleScorable()); + MultiCollector.wrap(c1, c2).getLeafCollector(ctx).setScorer(new Score()); reader.close(); dir.close(); @@ -498,7 +498,7 @@ public void testCollectionTermination() throws IOException { Collector mc = MultiCollector.wrap(c1, c2); LeafCollector lc = mc.getLeafCollector(ctx); - lc.setScorer(new SimpleScorable()); + lc.setScorer(new Score()); lc.collect(0); // OK assertTrue("c1's collect should be called", c1.collectCalled); assertTrue("c2's collect should be called", c2.collectCalled); @@ -549,21 +549,21 @@ private void doTestSetScorerOnCollectionTermination(boolean allowSkipNonCompetit LeafCollector lc = mc.getLeafCollector(ctx); assertFalse(c1.setScorerCalled); assertFalse(c2.setScorerCalled); - lc.setScorer(new SimpleScorable()); + lc.setScorer(new Score()); assertTrue(c1.setScorerCalled); assertTrue(c2.setScorerCalled); c1.setScorerCalled = false; c2.setScorerCalled = false; lc.collect(0); // OK - lc.setScorer(new SimpleScorable()); + lc.setScorer(new Score()); assertTrue(c1.setScorerCalled); assertTrue(c2.setScorerCalled); c1.setScorerCalled = false; c2.setScorerCalled = false; lc.collect(1); // OK, but c1 should terminate - lc.setScorer(new SimpleScorable()); + lc.setScorer(new Score()); assertFalse(c1.setScorerCalled); assertTrue(c2.setScorerCalled); c2.setScorerCalled = false; @@ -573,7 +573,7 @@ private void doTestSetScorerOnCollectionTermination(boolean allowSkipNonCompetit () -> { lc.collect(2); }); - lc.setScorer(new SimpleScorable()); + lc.setScorer(new Score()); assertFalse(c1.setScorerCalled); assertFalse(c2.setScorerCalled); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiCollectorManager.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollectorManager.java index c3b55b69feff..b25f9afaa721 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMultiCollectorManager.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiCollectorManager.java @@ -89,30 +89,19 @@ public void testCacheScoresIfNecessary() throws IOException { LeafReaderContext ctx = reader.leaves().get(0); // no collector needs scores => no caching - CollectorManager cm1 = - collectorManager(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class); - CollectorManager cm2 = - collectorManager(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class); - new MultiCollectorManager(cm1, cm2) - .newCollector() - .getLeafCollector(ctx) - .setScorer(new SimpleScorable()); + CollectorManager cm1 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, Score.class); + CollectorManager cm2 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, Score.class); + new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score()); // only one collector needs scores => no caching - cm1 = collectorManager(ScoreMode.COMPLETE, SimpleScorable.class); - cm2 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, SimpleScorable.class); - new MultiCollectorManager(cm1, cm2) - .newCollector() - .getLeafCollector(ctx) - .setScorer(new SimpleScorable()); + cm1 = collectorManager(ScoreMode.COMPLETE, Score.class); + cm2 = collectorManager(ScoreMode.COMPLETE_NO_SCORES, Score.class); + new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score()); // several collectors need scores => caching cm1 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class); cm2 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class); - new MultiCollectorManager(cm1, cm2) - .newCollector() - .getLeafCollector(ctx) - .setScorer(new SimpleScorable()); + new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score()); reader.close(); dir.close(); @@ -131,19 +120,13 @@ public void testScoreWrapping() throws IOException { CollectorManager cm2 = collectorManager( ScoreMode.TOP_SCORES, MultiCollector.MinCompetitiveScoreAwareScorable.class); - new MultiCollectorManager(cm1, cm2) - .newCollector() - .getLeafCollector(ctx) - .setScorer(new SimpleScorable()); + new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score()); // both wrapped collector managers need scores, but one is exhaustive, so they should // see a ScoreCachingWrappingScorer pass in as their scorer: cm1 = collectorManager(ScoreMode.COMPLETE, ScoreCachingWrappingScorer.class); cm2 = collectorManager(ScoreMode.TOP_SCORES, ScoreCachingWrappingScorer.class); - new MultiCollectorManager(cm1, cm2) - .newCollector() - .getLeafCollector(ctx) - .setScorer(new SimpleScorable()); + new MultiCollectorManager(cm1, cm2).newCollector().getLeafCollector(ctx).setScorer(new Score()); reader.close(); dir.close();