Merge pull request #16922 from jimferenczi/fix_match_query_tests

Fix sporadic error on match query test when a fuzziness of 0s is used.
This commit is contained in:
Jim Ferenczi 2016-03-03 14:29:47 +01:00
commit c996db731a
1 changed files with 6 additions and 9 deletions

View File

@ -196,22 +196,19 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
assertTrue(numericRangeQuery.includesMax());
double value;
double width = 0;
try {
double width;
if (queryBuilder.fieldName().equals(DATE_FIELD_NAME) == false) {
value = Double.parseDouble(queryBuilder.value().toString());
} catch (NumberFormatException e) {
// Maybe its a date
value = ISODateTimeFormat.dateTimeParser().parseMillis(queryBuilder.value().toString());
width = queryBuilder.fuzziness().asTimeValue().getMillis();
}
if (width == 0) {
if (queryBuilder.fuzziness().equals(Fuzziness.AUTO)) {
width = 1;
} else {
width = queryBuilder.fuzziness().asDouble();
}
} else {
value = ISODateTimeFormat.dateTimeParser().parseMillis(queryBuilder.value().toString());
width = queryBuilder.fuzziness().asTimeValue().getMillis();
}
assertEquals(value - width, numericRangeQuery.getMin().doubleValue(), width * .1);
assertEquals(value + width, numericRangeQuery.getMax().doubleValue(), width * .1);
}