TESTS: Make score Float#NaN when there is no max score (#33997)

* TESTS: Make score Float#NaN when there is no max score

Fixes test failure due to maxScore set to Float#MinValue instead
on Float#NaN. In addition the initial value for maxScore is set to
Float#NEGATIVE_INFINITY so it is an illegal value.

Closes #33993
This commit is contained in:
Ignacio Vera 2018-09-24 17:36:48 +02:00 committed by GitHub
parent 27ee5e87e4
commit df333ca305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -79,7 +79,7 @@ public class InternalTopHitsTests extends InternalAggregationTestCase<InternalTo
int requestedSize = between(1, 40); int requestedSize = between(1, 40);
int actualSize = between(0, requestedSize); int actualSize = between(0, requestedSize);
float maxScore = Float.MIN_VALUE; float maxScore = Float.NEGATIVE_INFINITY;
ScoreDoc[] scoreDocs = new ScoreDoc[actualSize]; ScoreDoc[] scoreDocs = new ScoreDoc[actualSize];
SearchHit[] hits = new SearchHit[actualSize]; SearchHit[] hits = new SearchHit[actualSize];
Set<Integer> usedDocIds = new HashSet<>(); Set<Integer> usedDocIds = new HashSet<>();
@ -112,7 +112,8 @@ public class InternalTopHitsTests extends InternalAggregationTestCase<InternalTo
} else { } else {
topDocs = new TopDocs(new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), scoreDocs); topDocs = new TopDocs(new TotalHits(totalHits, TotalHits.Relation.EQUAL_TO), scoreDocs);
} }
TopDocsAndMaxScore topDocsAndMaxScore = new TopDocsAndMaxScore(topDocs, maxScore); // Lucene's TopDocs initializes the maxScore to Float.NaN, if there is no maxScore
TopDocsAndMaxScore topDocsAndMaxScore = new TopDocsAndMaxScore(topDocs, maxScore == Float.NEGATIVE_INFINITY ? Float.NaN : maxScore);
return new InternalTopHits(name, from, requestedSize, topDocsAndMaxScore, searchHits, pipelineAggregators, metaData); return new InternalTopHits(name, from, requestedSize, topDocsAndMaxScore, searchHits, pipelineAggregators, metaData);
} }
@ -177,7 +178,7 @@ public class InternalTopHitsTests extends InternalAggregationTestCase<InternalTo
protected void assertReduced(InternalTopHits reduced, List<InternalTopHits> inputs) { protected void assertReduced(InternalTopHits reduced, List<InternalTopHits> inputs) {
SearchHits actualHits = reduced.getHits(); SearchHits actualHits = reduced.getHits();
List<Tuple<ScoreDoc, SearchHit>> allHits = new ArrayList<>(); List<Tuple<ScoreDoc, SearchHit>> allHits = new ArrayList<>();
float maxScore = Float.MIN_VALUE; float maxScore = Float.NEGATIVE_INFINITY;
long totalHits = 0; long totalHits = 0;
for (int input = 0; input < inputs.size(); input++) { for (int input = 0; input < inputs.size(); input++) {
SearchHits internalHits = inputs.get(input).getHits(); SearchHits internalHits = inputs.get(input).getHits();
@ -199,7 +200,7 @@ public class InternalTopHitsTests extends InternalAggregationTestCase<InternalTo
expectedHitsHits[i] = allHits.get(i).v2(); expectedHitsHits[i] = allHits.get(i).v2();
} }
// Lucene's TopDocs initializes the maxScore to Float.NaN, if there is no maxScore // Lucene's TopDocs initializes the maxScore to Float.NaN, if there is no maxScore
SearchHits expectedHits = new SearchHits(expectedHitsHits, totalHits, maxScore == Float.MIN_VALUE ? Float.NaN : maxScore); SearchHits expectedHits = new SearchHits(expectedHitsHits, totalHits, maxScore == Float.NEGATIVE_INFINITY ? Float.NaN : maxScore);
assertEqualsWithErrorMessageFromXContent(expectedHits, actualHits); assertEqualsWithErrorMessageFromXContent(expectedHits, actualHits);
} }