Fix AbstractStringFieldDataTestCase tests to account for TotalHits lower bound#4270
Conversation
Signed-off-by: Daniel Widdis <widdis@gmail.com>
| if (topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO) { | ||
| assertEquals(numDocs, topDocs.totalHits.value); | ||
| } else { | ||
| assertTrue(numDocs >= topDocs.totalHits.value); |
There was a problem hiding this comment.
Can't we just have the below
assertTrue(numDocs >= topDocs.totalHits.value);
rather the whole condition?
There was a problem hiding this comment.
In the test, our total documents (numDocs) is not always over 1000, and so it is more precise to test for equality in the 1/3 of cases where a more accurate result will apply.
This will protect against a bug where totalHits is always some small constant like 1, which would pass the lower bound test.
There was a problem hiding this comment.
(I might argue we could add another assertion that totalHits.value >= 1000 in this case, but that might be overkill.)
|
Pre-commit failing because of the usual Spotless |
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
|
Shouldn't we back port this PR to 2.x branch? |
|
I labeled it to backport, let's see. |
…or TotalHits lower bound (#4867) * Fix AbstractStringFieldDataTestCase tests to account for TotalHits lower bound (#4270) Fixes tests to account for TotalHits uncertainty as of Lucene 9. Signed-off-by: Daniel Widdis <widdis@gmail.com> (cherry picked from commit 4643620) * Added CHANGELOG. Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: Daniel Widdis <widdis@gmail.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
|
@dbwiddis Looking at the implementation here: not in love with conditions in specs. When is it one or the other? |
@dblock answering nearly two years later, sorry. The initial PR comment javadoc explains the difference. Lucene can compute the hit count and if it's > 1000 it makes it an approximate bound, indicated by the enum used for the conditional. |
Signed-off-by: Daniel Widdis widdis@gmail.com
Description
From Lucene's
IndexSearcherjavaDoc:The
AbstractStringFieldDataTestCaseassumed thetotalHitsvalue was exact.This fixes the test to test for either exact accuracy or lower bound, as appropriate.
Issues Resolved
Fixes #4238
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.