Skip to content

Commit 0720fe7

Browse files
committed
fix KeywordFieldBlockLoaderTests
1 parent 2a878cf commit 0720fe7

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,12 +1263,15 @@ private String originalName() {
12631263

12641264
@Override
12651265
protected SyntheticSourceSupport syntheticSourceSupport() {
1266+
/*
12661267
if (hasNormalizer()) {
12671268
// NOTE: no matter if we have doc values or not we use fallback synthetic source
12681269
// to store the original value whose doc values would be altered by the normalizer
12691270
return SyntheticSourceSupport.FALLBACK;
12701271
}
12711272
1273+
*/
1274+
12721275
if (fieldType.stored() || hasDocValues) {
12731276
return new SyntheticSourceSupport.Native(() -> syntheticFieldLoader(fullPath(), leafName()));
12741277
}

server/src/test/java/org/elasticsearch/index/mapper/blockloader/KeywordFieldBlockLoaderTests.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ public KeywordFieldBlockLoaderTests(Params params) {
2828
@SuppressWarnings("unchecked")
2929
@Override
3030
protected Object expected(Map<String, Object> fieldMapping, Object value, TestContext testContext) {
31-
var nullValue = (String) fieldMapping.get("null_value");
31+
String nullValue = (String) fieldMapping.get("null_value");
3232

33-
var ignoreAbove = fieldMapping.get("ignore_above") == null
33+
int ignoreAbove = fieldMapping.get("ignore_above") == null
3434
? Integer.MAX_VALUE
3535
: ((Number) fieldMapping.get("ignore_above")).intValue();
3636

37+
String normalizerName = (String) fieldMapping.get("normalizer");
38+
3739
if (value == null) {
38-
return convert(null, nullValue, ignoreAbove);
40+
return convert(null, nullValue, ignoreAbove, normalizerName);
3941
}
4042

4143
if (value instanceof String s) {
42-
return convert(s, nullValue, ignoreAbove);
44+
return convert(s, nullValue, ignoreAbove, normalizerName);
4345
}
4446

45-
Function<Stream<String>, Stream<BytesRef>> convertValues = s -> s.map(v -> convert(v, nullValue, ignoreAbove))
47+
Function<Stream<String>, Stream<BytesRef>> convertValues = s -> s.map(v -> convert(v, nullValue, ignoreAbove, normalizerName))
4648
.filter(Objects::nonNull);
4749

4850
boolean hasDocValues = hasDocValues(fieldMapping, false);
@@ -63,15 +65,21 @@ protected Object expected(Map<String, Object> fieldMapping, Object value, TestCo
6365
return maybeFoldList(resultList);
6466
}
6567

66-
private BytesRef convert(String value, String nullValue, int ignoreAbove) {
68+
private BytesRef convert(String value, String nullValue, int ignoreAbove, String normalizer) {
6769
if (value == null) {
6870
if (nullValue != null) {
6971
value = nullValue;
7072
} else {
7173
return null;
7274
}
7375
}
74-
76+
if (Objects.equals(normalizer, "lowercase")) {
77+
// hopefully not Turkish...
78+
value = value.toLowerCase();
79+
} else if (normalizer != null) {
80+
// we probably can't get here anyway, since MapperServiceTestCase only initializes the lowercase normalizer
81+
throw new IllegalArgumentException("normalizer [" + normalizer + "] not supported for block loader tests");
82+
}
7583
return value.length() <= ignoreAbove ? new BytesRef(value) : null;
7684
}
7785
}

0 commit comments

Comments
 (0)