From 66a8ad04e74d1b9d974a2e9e3d51dd75907de7fd Mon Sep 17 00:00:00 2001 From: jimczi Date: Mon, 21 Oct 2019 14:18:10 +0200 Subject: [PATCH] fix the logic to require the next float when checking the global minimum score --- .../org/apache/lucene/search/TopScoreDocCollector.java | 10 +++++----- .../org/apache/lucene/search/TestTopDocsCollector.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java b/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java index 303348d4c91..2c7710733d9 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java @@ -243,7 +243,7 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { * and a shared {@link MaxScoreAccumulator} to propagate the minimum score accross segments */ public static CollectorManager createSharedManager(int numHits, FieldDoc after, - int totalHitsThreshold, int maxDocs) { + int totalHitsThreshold) { return new CollectorManager<>() { private final HitsThresholdChecker hitsThresholdChecker = HitsThresholdChecker.createShared(totalHitsThreshold); @@ -305,9 +305,9 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { DocAndScore maxMinScore = minScoreAcc.get(); if (maxMinScore != null) { // since we tie-break on doc id and collect in doc id order we can require - // the next float if the global minimum score is set on a document that is - // greater than the ids in the current leaf - float score = maxMinScore.docID > docBase ? Math.nextUp(maxMinScore.score) : maxMinScore.score; + // the next float if the global minimum score is set on a document id that is + // smaller than the ids in the current leaf + float score = docBase > maxMinScore.docID ? Math.nextUp(maxMinScore.score) : maxMinScore.score; if (score > minCompetitiveScore) { assert hitsThresholdChecker.isThresholdReached(); scorer.setMinCompetitiveScore(score); @@ -328,7 +328,7 @@ public abstract class TopScoreDocCollector extends TopDocsCollector { scorer.setMinCompetitiveScore(localMinScore); totalHitsRelation = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO; minCompetitiveScore = localMinScore; - if (minScoreAcc!= null) { + if (minScoreAcc != null) { // we don't use the next float but we register the document // id so that other leaves can require it if they are after // the current maximum diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java index 94e57d40511..9e9d05dda57 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java @@ -129,7 +129,7 @@ public class TestTopDocsCollector extends LuceneTestCase { IndexSearcher searcher = new IndexSearcher(indexReader, service); CollectorManager collectorManager = TopScoreDocCollector.createSharedManager(numResults, - null, threshold, indexReader.maxDoc()); + null, threshold); return (TopDocs) searcher.search(q, collectorManager); } finally { @@ -417,7 +417,7 @@ public class TestTopDocsCollector extends LuceneTestCase { w.close(); CollectorManager manager = - TopScoreDocCollector.createSharedManager(2, null, 0, reader.maxDoc()); + TopScoreDocCollector.createSharedManager(2, null, 0); TopScoreDocCollector collector = manager.newCollector(); TopScoreDocCollector collector2 = manager.newCollector(); assertTrue(collector.minScoreAcc == collector2.minScoreAcc);