From 3adeac149d2dfaf5a44e188b1a2a6bed38b8546c Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Tue, 19 Jan 2016 12:28:57 +0100 Subject: [PATCH] Fix random fuzziness generation. For all query testing we offer the option to initialise them with random fuzziness objects. So far there is a chance to generate an edit distance based fuzziness for non-string fields. This is fixed by this change. Fixes the following test failure: http://build-us-00.elastic.co/job/es_core_master_small/6606/testReport/junit/org.elasticsearch.index.query/MatchQueryBuilderTests/testToQuery/ --- .../java/org/elasticsearch/common/unit/Fuzziness.java | 2 ++ .../elasticsearch/index/query/AbstractQueryTestCase.java | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java b/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java index 18641b8e418..24a727691cc 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java +++ b/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java @@ -67,6 +67,8 @@ public final class Fuzziness implements ToXContent, Writeable { /** * Creates a {@link Fuzziness} instance from an edit distance. The value must be one of [0, 1, 2] + * + * 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) { return new Fuzziness(edits); diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index cc54122d446..52aa7ea48f0 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -816,12 +816,6 @@ public abstract class AbstractQueryTestCase> } protected static Fuzziness randomFuzziness(String fieldName) { - if (randomBoolean()) { - return Fuzziness.fromEdits(randomIntBetween(0, 2)); - } - if (randomBoolean()) { - return Fuzziness.AUTO; - } switch (fieldName) { case INT_FIELD_NAME: return Fuzziness.build(randomIntBetween(3, 100)); @@ -830,6 +824,9 @@ public abstract class AbstractQueryTestCase> case DATE_FIELD_NAME: return Fuzziness.build(randomTimeValue()); default: + if (randomBoolean()) { + return Fuzziness.fromEdits(randomIntBetween(0, 2)); + } return Fuzziness.AUTO; } }