mirror of https://github.com/apache/lucene.git
revert some refactoring that made sense when updateMinCompetitiveScore was called eagerly
This commit is contained in:
parent
93d135e79d
commit
5895797fae
|
@ -124,8 +124,6 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
|||
@Override
|
||||
public void setScorer(Scorable scorer) throws IOException {
|
||||
super.setScorer(scorer);
|
||||
// reset the minimum competitive score
|
||||
minCompetitiveScore = 0f;
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
|
||||
|
@ -145,9 +143,9 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
|||
} else {
|
||||
collectedAllCompetitiveHits = true;
|
||||
}
|
||||
} else if (totalHitsRelation == TotalHits.Relation.EQUAL_TO) {
|
||||
// we can start setting the min competitive score if we just
|
||||
// reached totalHitsThreshold
|
||||
} else if (totalHitsRelation == Relation.EQUAL_TO) {
|
||||
// we just reached totalHitsThreshold, we can start setting the min
|
||||
// competitive score now
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
return;
|
||||
|
@ -167,8 +165,8 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
|||
add(slot, doc);
|
||||
if (queueFull) {
|
||||
comparator.setBottom(bottom.slot);
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,10 +239,8 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
|||
} else {
|
||||
collectedAllCompetitiveHits = true;
|
||||
}
|
||||
} else if (totalHitsRelation == TotalHits.Relation.EQUAL_TO) {
|
||||
// we can start setting the min competitive score if we just
|
||||
// reached totalHitsThreshold
|
||||
updateMinCompetitiveScore(scorer);
|
||||
} else if (totalHitsRelation == Relation.EQUAL_TO) {
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -282,8 +278,8 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
|||
queueFull = collectedHits == numHits;
|
||||
if (queueFull) {
|
||||
comparator.setBottom(bottom.slot);
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -343,30 +339,28 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
|
|||
}
|
||||
|
||||
protected void updateMinCompetitiveScore(Scorable scorer) throws IOException {
|
||||
if (canSetMinScore && hitsThresholdChecker.isThresholdReached()) {
|
||||
boolean hasChanged = false;
|
||||
if (canSetMinScore
|
||||
&& hitsThresholdChecker.isThresholdReached()
|
||||
&& ((bottomValueChecker != null && bottomValueChecker.getBottomValue() > 0) || queueFull)) {
|
||||
assert firstComparator != null;
|
||||
float bottomScore = 0f;
|
||||
|
||||
if (queueFull) {
|
||||
assert bottom != null && firstComparator != null;
|
||||
float localMinScore = firstComparator.value(bottom.slot);
|
||||
if (localMinScore > minCompetitiveScore) {
|
||||
hasChanged = true;
|
||||
minCompetitiveScore = localMinScore;
|
||||
if (bottomValueChecker != null) {
|
||||
bottomValueChecker.updateThreadLocalBottomValue(minCompetitiveScore);
|
||||
}
|
||||
bottomScore = firstComparator.value(bottom.slot);
|
||||
if (bottomValueChecker != null) {
|
||||
bottomValueChecker.updateThreadLocalBottomValue(bottomScore);
|
||||
}
|
||||
}
|
||||
if (bottomValueChecker != null) {
|
||||
float globalMinScore = bottomValueChecker.getBottomValue();
|
||||
if (globalMinScore > minCompetitiveScore) {
|
||||
hasChanged = true;
|
||||
minCompetitiveScore = globalMinScore;
|
||||
}
|
||||
}
|
||||
if (hasChanged) {
|
||||
scorer.setMinCompetitiveScore(minCompetitiveScore);
|
||||
totalHitsRelation = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO;
|
||||
|
||||
// Global bottom can only be greater than or equal to the local bottom score
|
||||
// The updating of global bottom score for this hit before getting here should
|
||||
// ensure that
|
||||
if (bottomValueChecker != null && bottomValueChecker.getBottomValue() > bottomScore) {
|
||||
bottomScore = bottomValueChecker.getBottomValue();
|
||||
}
|
||||
|
||||
scorer.setMinCompetitiveScore(bottomScore);
|
||||
totalHitsRelation = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,6 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
|
|||
@Override
|
||||
public void setScorer(Scorable scorer) throws IOException {
|
||||
super.setScorer(scorer);
|
||||
// reset the minimum competitive score
|
||||
minCompetitiveScore = 0f;
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
|
||||
|
@ -78,9 +76,9 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
|
|||
hitsThresholdChecker.incrementHitCount();
|
||||
|
||||
if (score <= pqTop.score) {
|
||||
if (totalHitsRelation == TotalHits.Relation.EQUAL_TO) {
|
||||
// we can start setting the min competitive score if we just
|
||||
// reached totalHitsThreshold
|
||||
if (totalHitsRelation == TotalHits.Relation.EQUAL_TO && hitsThresholdChecker.isThresholdReached()) {
|
||||
// we just reached totalHitsThreshold, we can start setting the min
|
||||
// competitive score now
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
// Since docs are returned in-order (i.e., increasing doc Id), a document
|
||||
|
@ -141,24 +139,24 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
|
|||
|
||||
if (score > after.score || (score == after.score && doc <= afterDoc)) {
|
||||
// hit was collected on a previous page
|
||||
if (totalHitsRelation == TotalHits.Relation.EQUAL_TO) {
|
||||
// we can start setting the min competitive score if we just
|
||||
// reached totalHitsThreshold
|
||||
if (totalHitsRelation == TotalHits.Relation.EQUAL_TO && hitsThresholdChecker.isThresholdReached()) {
|
||||
// we just reached totalHitsThreshold, we can start setting the min
|
||||
// competitive score now
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (score <= pqTop.score) {
|
||||
if (totalHitsRelation == TotalHits.Relation.EQUAL_TO) {
|
||||
// we can start setting the min competitive score if we just
|
||||
// reached totalHitsThreshold
|
||||
if (totalHitsRelation == TotalHits.Relation.EQUAL_TO && hitsThresholdChecker.isThresholdReached()) {
|
||||
// we just reached totalHitsThreshold, we can start setting the min
|
||||
// competitive score now
|
||||
updateMinCompetitiveScore(scorer);
|
||||
}
|
||||
|
||||
// Since docs are returned in-order (i.e., increasing doc Id), a document
|
||||
// with equal score to pqTop.score cannot compete since HitQueue favors
|
||||
// documents with lower doc Ids. Therefore reject those docs too.
|
||||
|
||||
return;
|
||||
}
|
||||
collectedHits++;
|
||||
|
@ -255,9 +253,6 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
|
|||
}
|
||||
|
||||
ScoreDoc pqTop;
|
||||
// the minimum competitive score that is currently
|
||||
// used by the underlying scorer (see setScorer)
|
||||
float minCompetitiveScore;
|
||||
final HitsThresholdChecker hitsThresholdChecker;
|
||||
final BottomValueChecker bottomValueChecker;
|
||||
|
||||
|
@ -288,44 +283,31 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
|
|||
return hitsThresholdChecker.scoreMode();
|
||||
}
|
||||
|
||||
public boolean isQueueFull() {
|
||||
return pqTop != null && pqTop.score != Float.NEGATIVE_INFINITY;
|
||||
}
|
||||
|
||||
protected void updateMinCompetitiveScore(Scorable scorer) throws IOException {
|
||||
if (hitsThresholdChecker.isThresholdReached()) {
|
||||
boolean hasChanged = false;
|
||||
if (isQueueFull()) {
|
||||
if (hitsThresholdChecker.isThresholdReached()
|
||||
&& ((bottomValueChecker != null && bottomValueChecker.getBottomValue() > 0)
|
||||
|| (pqTop != null && pqTop.score != Float.NEGATIVE_INFINITY))) { // -Infinity is the score of sentinels
|
||||
float bottomScore = 0f;
|
||||
|
||||
if (pqTop != null && pqTop.score != Float.NEGATIVE_INFINITY) {
|
||||
// since we tie-break on doc id and collect in doc id order, we can require
|
||||
// the next float
|
||||
float localMinScore = Math.nextUp(pqTop.score);
|
||||
if (localMinScore > minCompetitiveScore) {
|
||||
hasChanged = true;
|
||||
minCompetitiveScore = localMinScore;
|
||||
if (bottomValueChecker != null) {
|
||||
// we don't use the next float here since we register a minimum value
|
||||
// for other segments that might have smaller doc ids
|
||||
bottomValueChecker.updateThreadLocalBottomValue(pqTop.score);
|
||||
}
|
||||
bottomScore = Math.nextUp(pqTop.score);
|
||||
|
||||
if (bottomValueChecker != null) {
|
||||
bottomValueChecker.updateThreadLocalBottomValue(pqTop.score);
|
||||
}
|
||||
}
|
||||
|
||||
// Global bottom can only be greater than or equal to the local bottom score
|
||||
// The updating of global bottom score for this hit before getting here should
|
||||
// ensure that
|
||||
if (bottomValueChecker != null) {
|
||||
float globalMinScore = bottomValueChecker.getBottomValue();
|
||||
if (globalMinScore > minCompetitiveScore) {
|
||||
assert isQueueFull() == false || bottomValueChecker.getBottomValue() > Math.nextUp(pqTop.score);
|
||||
hasChanged = true;
|
||||
minCompetitiveScore = bottomValueChecker.getBottomValue();
|
||||
}
|
||||
if (bottomValueChecker != null && bottomValueChecker.getBottomValue() > bottomScore) {
|
||||
bottomScore = bottomValueChecker.getBottomValue();
|
||||
}
|
||||
|
||||
if (hasChanged) {
|
||||
scorer.setMinCompetitiveScore(minCompetitiveScore);
|
||||
totalHitsRelation = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO;
|
||||
}
|
||||
scorer.setMinCompetitiveScore(bottomScore);
|
||||
totalHitsRelation = TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue