mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
* #27189 Fixed rounding of bounds in scaled float comparison * #27189 more assertions from CR
This commit is contained in:
parent
0635778c90
commit
8f0f024507
@ -256,19 +256,19 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
||||
failIfNotIndexed();
|
||||
Long lo = null;
|
||||
if (lowerTerm != null) {
|
||||
double dValue = parse(lowerTerm);
|
||||
double dValue = parse(lowerTerm) * scalingFactor;
|
||||
if (includeLower == false) {
|
||||
dValue = Math.nextUp(dValue);
|
||||
}
|
||||
lo = Math.round(Math.ceil(dValue * scalingFactor));
|
||||
lo = Math.round(Math.ceil(dValue));
|
||||
}
|
||||
Long hi = null;
|
||||
if (upperTerm != null) {
|
||||
double dValue = parse(upperTerm);
|
||||
double dValue = parse(upperTerm) * scalingFactor;
|
||||
if (includeUpper == false) {
|
||||
dValue = Math.nextDown(dValue);
|
||||
}
|
||||
hi = Math.round(Math.floor(dValue * scalingFactor));
|
||||
hi = Math.round(Math.floor(dValue));
|
||||
}
|
||||
Query query = NumberFieldMapper.NumberType.LONG.rangeQuery(name(), lo, hi, true, true, hasDocValues());
|
||||
if (boost() != 1f) {
|
||||
|
@ -124,6 +124,42 @@ public class ScaledFloatFieldTypeTests extends FieldTypeTestCase {
|
||||
IOUtils.close(reader, dir);
|
||||
}
|
||||
|
||||
public void testRoundsUpperBoundCorrectly() {
|
||||
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
|
||||
ft.setName("scaled_float");
|
||||
ft.setScalingFactor(100.0);
|
||||
Query scaledFloatQ = ft.rangeQuery(null, 0.1, true, false, null);
|
||||
assertEquals("scaled_float:[-9223372036854775808 TO 9]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(null, 0.1, true, true, null);
|
||||
assertEquals("scaled_float:[-9223372036854775808 TO 10]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(null, 0.095, true, false, null);
|
||||
assertEquals("scaled_float:[-9223372036854775808 TO 9]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(null, 0.095, true, true, null);
|
||||
assertEquals("scaled_float:[-9223372036854775808 TO 9]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(null, 0.105, true, false, null);
|
||||
assertEquals("scaled_float:[-9223372036854775808 TO 10]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(null, 0.105, true, true, null);
|
||||
assertEquals("scaled_float:[-9223372036854775808 TO 10]", scaledFloatQ.toString());
|
||||
}
|
||||
|
||||
public void testRoundsLowerBoundCorrectly() {
|
||||
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
|
||||
ft.setName("scaled_float");
|
||||
ft.setScalingFactor(100.0);
|
||||
Query scaledFloatQ = ft.rangeQuery(-0.1, null, false, true, null);
|
||||
assertEquals("scaled_float:[-9 TO 9223372036854775807]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(-0.1, null, true, true, null);
|
||||
assertEquals("scaled_float:[-10 TO 9223372036854775807]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(-0.095, null, false, true, null);
|
||||
assertEquals("scaled_float:[-9 TO 9223372036854775807]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(-0.095, null, true, true, null);
|
||||
assertEquals("scaled_float:[-9 TO 9223372036854775807]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(-0.105, null, false, true, null);
|
||||
assertEquals("scaled_float:[-10 TO 9223372036854775807]", scaledFloatQ.toString());
|
||||
scaledFloatQ = ft.rangeQuery(-0.105, null, true, true, null);
|
||||
assertEquals("scaled_float:[-10 TO 9223372036854775807]", scaledFloatQ.toString());
|
||||
}
|
||||
|
||||
public void testValueForSearch() {
|
||||
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
|
||||
ft.setName("scaled_float");
|
||||
|
Loading…
x
Reference in New Issue
Block a user