From 3b3f9600c2ea6023f5400a364c0921ba29667584 Mon Sep 17 00:00:00 2001 From: Greg Miller Date: Thu, 26 Aug 2021 14:44:52 -0700 Subject: [PATCH] Fix a DrillSideways unit test I broke when adding more tests in LUCENE-10060 (#268) --- .../lucene/facet/TestDrillSideways.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java index 567736dbbbb..4250fbf7332 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java @@ -216,7 +216,8 @@ public class TestDrillSideways extends FacetTestCase { // We'll use a CollectorManager to trigger the trickiest caching behavior: SimpleCollectorManager collectorManager = - new SimpleCollectorManager(10, Comparator.comparing(cr -> cr.id)); + new SimpleCollectorManager( + 10, Comparator.comparing(cr -> cr.id), ScoreMode.COMPLETE_NO_SCORES); // Make sure our CM produces Collectors that _do not_ need scores to ensure IndexSearcher tries // to cache: assertFalse(collectorManager.newCollector().scoreMode().needsScores()); @@ -234,7 +235,7 @@ public class TestDrillSideways extends FacetTestCase { concurrentResult.facets.getTopChildren(10, "Size").toString()); // Now do the same thing but use a Collector directly: - SimpleCollector collector = new SimpleCollector(); + SimpleCollector collector = new SimpleCollector(ScoreMode.COMPLETE_NO_SCORES); // Make sure our Collector _does not_ need scores to ensure IndexSearcher tries to cache: assertFalse(collector.scoreMode().needsScores()); // If we incorrectly cache here, the "sideways" FacetsCollectors will get populated with counts @@ -1284,6 +1285,12 @@ public class TestDrillSideways extends FacetTestCase { CollectorManager> manager = new SimpleCollectorManager(numDocs, Comparator.comparing(cr -> cr.id)); + // Because we validate the scores computed through DrillSideways against those found through + // a direct search + // against IndexSearcher, make sure our Collectors announce themselves as requiring scores. + // See conversation + // in LUCENE-10060 where this bug was introduced and then discovered: + assertTrue(manager.newCollector().scoreMode.needsScores()); DrillSideways.ConcurrentDrillSidewaysResult> cr = ds.search(ddq, manager); actual.results = cr.collectorResult; actual.resultCount = new TotalHits(actual.results.size(), TotalHits.Relation.EQUAL_TO); @@ -1395,8 +1402,13 @@ public class TestDrillSideways extends FacetTestCase { private static class SimpleCollector implements Collector { + private final ScoreMode scoreMode; final List hits = new ArrayList<>(); + SimpleCollector(ScoreMode scoreMode) { + this.scoreMode = scoreMode; + } + @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { @@ -1423,7 +1435,7 @@ public class TestDrillSideways extends FacetTestCase { @Override public ScoreMode scoreMode() { - return ScoreMode.COMPLETE_NO_SCORES; + return scoreMode; } } @@ -1431,15 +1443,22 @@ public class TestDrillSideways extends FacetTestCase { implements CollectorManager> { private final int numDocs; private final Comparator comparator; + private final ScoreMode scoreMode; SimpleCollectorManager(int numDocs, Comparator comparator) { + this(numDocs, comparator, ScoreMode.COMPLETE); + } + + SimpleCollectorManager( + int numDocs, Comparator comparator, ScoreMode scoreMode) { this.numDocs = numDocs; this.comparator = comparator; + this.scoreMode = scoreMode; } @Override public SimpleCollector newCollector() { - return new SimpleCollector(); + return new SimpleCollector(scoreMode); } @Override