Merge pull request #16085 from MaineC/bug-fix/random-fuzziness-date

Fix for MatchQueryBuilderTests.testToQuery random fuzziness generation caused test failure.

Relates to #13284
This commit is contained in:
Isabel Drost-Fromm 2016-01-19 13:26:44 +01:00
commit e7aae1b79e
2 changed files with 5 additions and 6 deletions

View File

@ -67,6 +67,8 @@ public final class Fuzziness implements ToXContent, Writeable<Fuzziness> {
/** /**
* Creates a {@link Fuzziness} instance from an edit distance. The value must be one of <tt>[0, 1, 2]</tt> * Creates a {@link Fuzziness} instance from an edit distance. The value must be one of <tt>[0, 1, 2]</tt>
*
* Note: Using this method only makes sense if the field you are applying Fuzziness to is some sort of string.
*/ */
public static Fuzziness fromEdits(int edits) { public static Fuzziness fromEdits(int edits) {
return new Fuzziness(edits); return new Fuzziness(edits);

View File

@ -816,12 +816,6 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
} }
protected static Fuzziness randomFuzziness(String fieldName) { protected static Fuzziness randomFuzziness(String fieldName) {
if (randomBoolean()) {
return Fuzziness.fromEdits(randomIntBetween(0, 2));
}
if (randomBoolean()) {
return Fuzziness.AUTO;
}
switch (fieldName) { switch (fieldName) {
case INT_FIELD_NAME: case INT_FIELD_NAME:
return Fuzziness.build(randomIntBetween(3, 100)); return Fuzziness.build(randomIntBetween(3, 100));
@ -830,6 +824,9 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
case DATE_FIELD_NAME: case DATE_FIELD_NAME:
return Fuzziness.build(randomTimeValue()); return Fuzziness.build(randomTimeValue());
default: default:
if (randomBoolean()) {
return Fuzziness.fromEdits(randomIntBetween(0, 2));
}
return Fuzziness.AUTO; return Fuzziness.AUTO;
} }
} }