/
AnnotatedTextFieldTypeTests.java
43 lines (36 loc) · 1.76 KB
/
AnnotatedTextFieldTypeTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.index.mapper.annotatedtext;
import org.apache.lucene.queries.intervals.Intervals;
import org.apache.lucene.queries.intervals.IntervalsSource;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class AnnotatedTextFieldTypeTests extends FieldTypeTestCase {
public void testIntervals() throws IOException {
MappedFieldType ft = new AnnotatedTextFieldMapper.AnnotatedTextFieldType("field", Collections.emptyMap());
IntervalsSource source = ft.termIntervals(new BytesRef("donald"), null);
assertEquals(Intervals.term("donald"), source);
}
public void testFetchSourceValue() throws IOException {
MappedFieldType fieldType = new AnnotatedTextFieldMapper.Builder(
"field",
IndexVersion.current(),
createDefaultIndexAnalyzers(),
false
).build(MapperBuilderContext.root(false, false)).fieldType();
assertEquals(List.of("value"), fetchSourceValue(fieldType, "value"));
assertEquals(List.of("42"), fetchSourceValue(fieldType, 42L));
assertEquals(List.of("true"), fetchSourceValue(fieldType, true));
}
}