Merge pull request #16056 from MaineC/bug-fix/15860

Fix for MatchQueryBuilderTests.testToQuery test failure

Relates to #15860
This commit is contained in:
Isabel Drost-Fromm 2016-01-19 09:57:46 +01:00
commit 3b27dce94f
1 changed files with 7 additions and 8 deletions

View File

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