From acd526a54fc474784373ad032bcb92289d519d6c Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 3 Oct 2025 16:57:00 +0100 Subject: [PATCH] Move intervals methods to TextFamilyFieldType --- .../extras/MatchOnlyTextFieldTypeTests.java | 12 ++-- .../AnnotatedTextFieldTypeTests.java | 3 +- .../index/mapper/MappedFieldType.java | 68 ------------------ .../index/mapper/PlaceHolderFieldMapper.java | 44 ------------ .../index/mapper/TextFamilyFieldType.java | 70 +++++++++++++++++++ .../index/query/IntervalQueryBuilder.java | 8 ++- .../index/query/IntervalsSourceProvider.java | 55 +++++++++------ .../ConstantScoreTextFieldTypeTests.java | 12 ++-- .../index/mapper/TextFieldTypeTests.java | 12 ++-- .../PatternTextFieldTypeTests.java | 12 ++-- 10 files changed, 135 insertions(+), 161 deletions(-) diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java index 8e70945fc2a76..74f1f9a16a6d6 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java @@ -173,14 +173,14 @@ public void testPhrasePrefixQuery() throws IOException { } public void testTermIntervals() { - MappedFieldType ft = new MatchOnlyTextFieldType("field"); + MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field"); IntervalsSource termIntervals = ft.termIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(termIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals(Intervals.term(new BytesRef("foo")), ((SourceIntervalsSource) termIntervals).getIntervalsSource()); } public void testPrefixIntervals() { - MappedFieldType ft = new MatchOnlyTextFieldType("field"); + MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field"); IntervalsSource prefixIntervals = ft.prefixIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(prefixIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( @@ -190,7 +190,7 @@ public void testPrefixIntervals() { } public void testWildcardIntervals() { - MappedFieldType ft = new MatchOnlyTextFieldType("field"); + MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field"); IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(wildcardIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( @@ -200,7 +200,7 @@ public void testWildcardIntervals() { } public void testRegexpIntervals() { - MappedFieldType ft = new MatchOnlyTextFieldType("field"); + MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field"); IntervalsSource regexpIntervals = ft.regexpIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(regexpIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( @@ -210,13 +210,13 @@ public void testRegexpIntervals() { } public void testFuzzyIntervals() { - MappedFieldType ft = new MatchOnlyTextFieldType("field"); + MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field"); IntervalsSource fuzzyIntervals = ft.fuzzyIntervals("foo", 1, 2, true, MOCK_CONTEXT); assertThat(fuzzyIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); } public void testRangeIntervals() { - MappedFieldType ft = new MatchOnlyTextFieldType("field"); + MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field"); IntervalsSource rangeIntervals = ft.rangeIntervals(new BytesRef("foo"), new BytesRef("foo1"), true, true, MOCK_CONTEXT); assertThat(rangeIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( diff --git a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldTypeTests.java b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldTypeTests.java index 08621a435a576..ea93058d3e890 100644 --- a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldTypeTests.java +++ b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldTypeTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.index.mapper.FieldTypeTestCase; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperBuilderContext; +import org.elasticsearch.index.mapper.TextFamilyFieldType; import java.io.IOException; import java.util.Collections; @@ -24,7 +25,7 @@ public class AnnotatedTextFieldTypeTests extends FieldTypeTestCase { public void testIntervals() throws IOException { - MappedFieldType ft = new AnnotatedTextFieldMapper.AnnotatedTextFieldType("field", Collections.emptyMap()); + TextFamilyFieldType ft = new AnnotatedTextFieldMapper.AnnotatedTextFieldType("field", Collections.emptyMap()); IntervalsSource source = ft.termIntervals(new BytesRef("donald"), null); assertEquals(Intervals.term("donald"), source); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java index 7c0718a6d14a2..a6f2aef4b35db 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java @@ -14,7 +14,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; -import org.apache.lucene.queries.intervals.IntervalsSource; import org.apache.lucene.queries.spans.SpanMultiTermQueryWrapper; import org.apache.lucene.queries.spans.SpanQuery; import org.apache.lucene.search.BooleanClause.Occur; @@ -24,7 +23,6 @@ import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; -import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.automaton.Automaton; import org.apache.lucene.util.automaton.CharacterRunAutomaton; import org.elasticsearch.ElasticsearchException; @@ -438,72 +436,6 @@ public Query distanceFeatureQuery(Object origin, String pivot, SearchExecutionCo ); } - /** - * Create an {@link IntervalsSource} for the given term. - */ - public IntervalsSource termIntervals(BytesRef term, SearchExecutionContext context) { - throw new IllegalArgumentException( - "Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]" - ); - } - - /** - * Create an {@link IntervalsSource} for the given prefix. - */ - public IntervalsSource prefixIntervals(BytesRef prefix, SearchExecutionContext context) { - throw new IllegalArgumentException( - "Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]" - ); - } - - /** - * Create a fuzzy {@link IntervalsSource} for the given term. - */ - public IntervalsSource fuzzyIntervals( - String term, - int maxDistance, - int prefixLength, - boolean transpositions, - SearchExecutionContext context - ) { - throw new IllegalArgumentException( - "Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]" - ); - } - - /** - * Create a wildcard {@link IntervalsSource} for the given pattern. - */ - public IntervalsSource wildcardIntervals(BytesRef pattern, SearchExecutionContext context) { - throw new IllegalArgumentException( - "Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]" - ); - } - - /** - * Create a regexp {@link IntervalsSource} for the given pattern. - */ - public IntervalsSource regexpIntervals(BytesRef pattern, SearchExecutionContext context) { - throw new IllegalArgumentException( - "Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]" - ); - } - - /** - * Create a range {@link IntervalsSource} for the given ranges - */ - public IntervalsSource rangeIntervals( - BytesRef lowerTerm, - BytesRef upperTerm, - boolean includeLower, - boolean includeUpper, - SearchExecutionContext context - ) { - throw new IllegalArgumentException( - "Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]" - ); - } - /** * An enum used to describe the relation between the range of terms in a * shard when compared with a query range diff --git a/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java index 7c5dfa2be0449..adfc70d1e5f80 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/PlaceHolderFieldMapper.java @@ -10,12 +10,10 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.queries.intervals.IntervalsSource; import org.apache.lucene.queries.spans.SpanMultiTermQueryWrapper; import org.apache.lucene.queries.spans.SpanQuery; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.time.DateMathParser; import org.elasticsearch.common.unit.Fuzziness; @@ -222,48 +220,6 @@ public Query distanceFeatureQuery(Object origin, String pivot, SearchExecutionCo throw new QueryShardException(context, fail("distance feature query")); } - @Override - public IntervalsSource termIntervals(BytesRef term, SearchExecutionContext context) { - throw new QueryShardException(context, fail("term intervals query")); - } - - @Override - public IntervalsSource prefixIntervals(BytesRef prefix, SearchExecutionContext context) { - throw new QueryShardException(context, fail("term intervals query")); - } - - @Override - public IntervalsSource fuzzyIntervals( - String term, - int maxDistance, - int prefixLength, - boolean transpositions, - SearchExecutionContext context - ) { - throw new QueryShardException(context, fail("fuzzy intervals query")); - } - - @Override - public IntervalsSource wildcardIntervals(BytesRef pattern, SearchExecutionContext context) { - throw new QueryShardException(context, fail("wildcard intervals query")); - } - - @Override - public IntervalsSource regexpIntervals(BytesRef pattern, SearchExecutionContext context) { - throw new QueryShardException(context, fail("regexp intervals query")); - } - - @Override - public IntervalsSource rangeIntervals( - BytesRef lowerTerm, - BytesRef upperTerm, - boolean includeLower, - boolean includeUpper, - SearchExecutionContext context - ) { - throw new QueryShardException(context, fail("range intervals query")); - } - @Override public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext) { throw new IllegalArgumentException(fail("aggregation or sorts")); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFamilyFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFamilyFieldType.java index d954e508929c6..96cc591e0e4b8 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFamilyFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFamilyFieldType.java @@ -9,6 +9,10 @@ package org.elasticsearch.index.mapper; +import org.apache.lucene.queries.intervals.IntervalsSource; +import org.apache.lucene.util.BytesRef; +import org.elasticsearch.index.query.SearchExecutionContext; + import java.util.Map; /** @@ -50,4 +54,70 @@ public String syntheticSourceFallbackFieldName() { return isSyntheticSourceEnabled ? name() + "._original" : null; } + /** + * Create an {@link IntervalsSource} for the given term. + */ + public IntervalsSource termIntervals(BytesRef term, SearchExecutionContext context) { + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]" + ); + } + + /** + * Create an {@link IntervalsSource} for the given prefix. + */ + public IntervalsSource prefixIntervals(BytesRef prefix, SearchExecutionContext context) { + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]" + ); + } + + /** + * Create a fuzzy {@link IntervalsSource} for the given term. + */ + public IntervalsSource fuzzyIntervals( + String term, + int maxDistance, + int prefixLength, + boolean transpositions, + SearchExecutionContext context + ) { + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]" + ); + } + + /** + * Create a wildcard {@link IntervalsSource} for the given pattern. + */ + public IntervalsSource wildcardIntervals(BytesRef pattern, SearchExecutionContext context) { + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]" + ); + } + + /** + * Create a regexp {@link IntervalsSource} for the given pattern. + */ + public IntervalsSource regexpIntervals(BytesRef pattern, SearchExecutionContext context) { + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]" + ); + } + + /** + * Create a range {@link IntervalsSource} for the given ranges + */ + public IntervalsSource rangeIntervals( + BytesRef lowerTerm, + BytesRef upperTerm, + boolean includeLower, + boolean includeUpper, + SearchExecutionContext context + ) { + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]" + ); + } + } diff --git a/server/src/main/java/org/elasticsearch/index/query/IntervalQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/IntervalQueryBuilder.java index 8a62e1d2856b5..384f7b21f097b 100644 --- a/server/src/main/java/org/elasticsearch/index/query/IntervalQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/IntervalQueryBuilder.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.mapper.MappedFieldType; +import org.elasticsearch.index.mapper.TextFamilyFieldType; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; @@ -133,7 +134,12 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException { return new MatchNoDocsQuery(); } } - return new IntervalQuery(field, sourceProvider.getSource(context, fieldType)); + if (fieldType instanceof TextFamilyFieldType tfft) { + return new IntervalQuery(field, sourceProvider.getSource(context, tfft)); + } + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + field + "] which is of type [" + fieldType.typeName() + "]" + ); } @Override diff --git a/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java b/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java index 01e4678c6d39c..0b95b873ecdfe 100644 --- a/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java +++ b/server/src/main/java/org/elasticsearch/index/query/IntervalsSourceProvider.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.mapper.MappedFieldType; +import org.elasticsearch.index.mapper.TextFamilyFieldType; import org.elasticsearch.script.Script; import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.ObjectParser; @@ -54,7 +55,7 @@ */ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXContentFragment { - public abstract IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) throws IOException; + public abstract IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) throws IOException; public abstract void extractFields(Set fields); @@ -103,6 +104,19 @@ private static IntervalsSourceProvider parseInnerIntervals(XContentParser parser return isp; } + private static TextFamilyFieldType useField(MappedFieldType fieldType) { + if (fieldType instanceof TextFamilyFieldType) { + return (TextFamilyFieldType) fieldType; + } + throw new IllegalArgumentException( + "Can only use interval queries on text fields - not on [" + + fieldType.name() + + "] which is of type [" + + fieldType.typeName() + + "]" + ); + } + public static class Match extends IntervalsSourceProvider { public static final String NAME = "match"; @@ -133,7 +147,7 @@ public Match(StreamInput in) throws IOException { } private static IntervalsSource intervals( - MappedFieldType fieldType, + TextFamilyFieldType fieldType, String text, int maxGaps, boolean ordered, @@ -150,14 +164,13 @@ protected IntervalsSource termIntervals(BytesRef term) { } @Override - public IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) throws IOException { + public IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) throws IOException { NamedAnalyzer analyzer = null; if (this.analyzer != null) { analyzer = context.getIndexAnalyzers().get(this.analyzer); } if (useField != null) { - fieldType = context.getFieldType(useField); - assert fieldType != null; + fieldType = useField(context.getFieldType(useField)); } if (analyzer == null) { analyzer = fieldType.getTextSearchInfo().searchAnalyzer(); @@ -296,7 +309,7 @@ public Disjunction(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext ctx, MappedFieldType fieldType) throws IOException { + public IntervalsSource getSource(SearchExecutionContext ctx, TextFamilyFieldType fieldType) throws IOException { List sources = new ArrayList<>(); for (IntervalsSourceProvider provider : subSources) { sources.add(provider.getSource(ctx, fieldType)); @@ -407,7 +420,7 @@ public Combine(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext ctx, MappedFieldType fieldType) throws IOException { + public IntervalsSource getSource(SearchExecutionContext ctx, TextFamilyFieldType fieldType) throws IOException { List ss = new ArrayList<>(); for (IntervalsSourceProvider provider : subSources) { ss.add(provider.getSource(ctx, fieldType)); @@ -534,14 +547,13 @@ public Prefix(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) throws IOException { + public IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) throws IOException { NamedAnalyzer analyzer = null; if (this.analyzer != null) { analyzer = context.getIndexAnalyzers().get(this.analyzer); } if (useField != null) { - fieldType = context.getFieldType(useField); - assert fieldType != null; + fieldType = useField(context.getFieldType(useField)); } if (analyzer == null) { analyzer = fieldType.getTextSearchInfo().searchAnalyzer(); @@ -652,14 +664,13 @@ public Wildcard(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) { + public IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) { NamedAnalyzer analyzer = null; if (this.analyzer != null) { analyzer = context.getIndexAnalyzers().get(this.analyzer); } if (useField != null) { - fieldType = context.getFieldType(useField); - assert fieldType != null; + fieldType = useField(context.getFieldType(useField)); } if (analyzer == null) { analyzer = fieldType.getTextSearchInfo().searchAnalyzer(); @@ -770,14 +781,13 @@ public Regexp(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) { + public IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) { NamedAnalyzer analyzer = null; if (this.analyzer != null) { analyzer = context.getIndexAnalyzers().get(this.analyzer); } if (useField != null) { - fieldType = context.getFieldType(useField); - assert fieldType != null; + fieldType = useField(context.getFieldType(useField)); } if (analyzer == null) { analyzer = fieldType.getTextSearchInfo().searchAnalyzer(); @@ -902,14 +912,13 @@ public Fuzzy(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) { + public IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) { NamedAnalyzer analyzer = null; if (this.analyzer != null) { analyzer = context.getIndexAnalyzers().get(this.analyzer); } if (useField != null) { - fieldType = context.getFieldType(useField); - assert fieldType != null; + fieldType = useField(context.getFieldType(useField)); } if (analyzer == null) { analyzer = fieldType.getTextSearchInfo().searchAnalyzer(); @@ -1063,14 +1072,13 @@ public Range(StreamInput in) throws IOException { } @Override - public IntervalsSource getSource(SearchExecutionContext context, MappedFieldType fieldType) { + public IntervalsSource getSource(SearchExecutionContext context, TextFamilyFieldType fieldType) { NamedAnalyzer analyzer = null; if (this.analyzer != null) { analyzer = context.getIndexAnalyzers().get(this.analyzer); } if (useField != null) { - fieldType = context.getFieldType(useField); - assert fieldType != null; + fieldType = useField(context.getFieldType(useField)); } if (analyzer == null) { analyzer = fieldType.getTextSearchInfo().searchAnalyzer(); @@ -1264,7 +1272,8 @@ public IntervalFilter(StreamInput in) throws IOException { } } - public IntervalsSource filter(IntervalsSource input, SearchExecutionContext context, MappedFieldType fieldType) throws IOException { + public IntervalsSource filter(IntervalsSource input, SearchExecutionContext context, TextFamilyFieldType fieldType) + throws IOException { if (script != null) { IntervalFilterScript ifs = context.compile(script, IntervalFilterScript.CONTEXT).newInstance(); return new ScriptFilterSource(input, script.getIdOrCode(), ifs); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java index e454a4ffa0c8d..802903fb32c9a 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ConstantScoreTextFieldTypeTests.java @@ -224,31 +224,31 @@ public void testNormalizedWildcardQuery() { } public void testTermIntervals() throws IOException { - MappedFieldType ft = createFieldType(); + ConstantScoreTextFieldType ft = createFieldType(); IntervalsSource termIntervals = ft.termIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.term(new BytesRef("foo")), termIntervals); } public void testPrefixIntervals() throws IOException { - MappedFieldType ft = createFieldType(); + ConstantScoreTextFieldType ft = createFieldType(); IntervalsSource prefixIntervals = ft.prefixIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.prefix(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), prefixIntervals); } public void testWildcardIntervals() throws IOException { - MappedFieldType ft = createFieldType(); + ConstantScoreTextFieldType ft = createFieldType(); IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.wildcard(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), wildcardIntervals); } public void testRegexpIntervals() { - MappedFieldType ft = createFieldType(); + ConstantScoreTextFieldType ft = createFieldType(); IntervalsSource regexpIntervals = ft.regexpIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.regexp(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), regexpIntervals); } public void testFuzzyIntervals() throws IOException { - MappedFieldType ft = createFieldType(); + ConstantScoreTextFieldType ft = createFieldType(); IntervalsSource fuzzyIntervals = ft.fuzzyIntervals("foo", 1, 2, true, MOCK_CONTEXT); FuzzyQuery fq = new FuzzyQuery(new Term("field", "foo"), 1, 2, 128, true); IntervalsSource expectedIntervals = Intervals.multiterm(fq.getAutomata(), IndexSearcher.getMaxClauseCount(), "foo"); @@ -270,7 +270,7 @@ public void testWildcardIntervalsWithIndexedPrefixes() { } public void testRangeIntervals() { - MappedFieldType ft = createFieldType(); + ConstantScoreTextFieldType ft = createFieldType(); IntervalsSource rangeIntervals = ft.rangeIntervals(new BytesRef("foo"), new BytesRef("foo1"), true, true, MOCK_CONTEXT); assertEquals( Intervals.range(new BytesRef("foo"), new BytesRef("foo1"), true, true, IndexSearcher.getMaxClauseCount()), diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java index 82f1d3a0b687c..fcab101da9baa 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldTypeTests.java @@ -247,31 +247,31 @@ public void testNormalizedWildcardQuery() { } public void testTermIntervals() throws IOException { - MappedFieldType ft = createFieldType(); + TextFieldType ft = createFieldType(); IntervalsSource termIntervals = ft.termIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.term(new BytesRef("foo")), termIntervals); } public void testPrefixIntervals() throws IOException { - MappedFieldType ft = createFieldType(); + TextFieldType ft = createFieldType(); IntervalsSource prefixIntervals = ft.prefixIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.prefix(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), prefixIntervals); } public void testWildcardIntervals() { - MappedFieldType ft = createFieldType(); + TextFieldType ft = createFieldType(); IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.wildcard(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), wildcardIntervals); } public void testRegexpIntervals() { - MappedFieldType ft = createFieldType(); + TextFieldType ft = createFieldType(); IntervalsSource regexpIntervals = ft.regexpIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertEquals(Intervals.regexp(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), regexpIntervals); } public void testFuzzyIntervals() { - MappedFieldType ft = createFieldType(); + TextFieldType ft = createFieldType(); IntervalsSource fuzzyIntervals = ft.fuzzyIntervals("foo", 1, 2, true, MOCK_CONTEXT); FuzzyQuery fq = new FuzzyQuery(new Term("field", "foo"), 1, 2, 128, true); IntervalsSource expectedIntervals = Intervals.multiterm(fq.getAutomata(), IndexSearcher.getMaxClauseCount(), "foo"); @@ -293,7 +293,7 @@ public void testWildcardIntervalsWithIndexedPrefixes() { } public void testRangeIntervals() { - MappedFieldType ft = createFieldType(); + TextFieldType ft = createFieldType(); IntervalsSource rangeIntervals = ft.rangeIntervals(new BytesRef("foo"), new BytesRef("foo1"), true, true, MOCK_CONTEXT); assertEquals( Intervals.range(new BytesRef("foo"), new BytesRef("foo1"), true, true, IndexSearcher.getMaxClauseCount()), diff --git a/x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextFieldTypeTests.java b/x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextFieldTypeTests.java index 46856aee89742..f8c0d711aa367 100644 --- a/x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextFieldTypeTests.java +++ b/x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextFieldTypeTests.java @@ -140,14 +140,14 @@ public void testPhrasePrefixQuery() throws IOException { } public void testTermIntervals() { - MappedFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); + PatternTextFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); IntervalsSource termIntervals = ft.termIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(termIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals(Intervals.term(new BytesRef("foo")), ((SourceIntervalsSource) termIntervals).getIntervalsSource()); } public void testPrefixIntervals() { - MappedFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); + PatternTextFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); IntervalsSource prefixIntervals = ft.prefixIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(prefixIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( @@ -157,7 +157,7 @@ public void testPrefixIntervals() { } public void testWildcardIntervals() { - MappedFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); + PatternTextFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(wildcardIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( @@ -167,7 +167,7 @@ public void testWildcardIntervals() { } public void testRegexpIntervals() { - MappedFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); + PatternTextFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); IntervalsSource regexpIntervals = ft.regexpIntervals(new BytesRef("foo"), MOCK_CONTEXT); assertThat(regexpIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals( @@ -177,13 +177,13 @@ public void testRegexpIntervals() { } public void testFuzzyIntervals() { - MappedFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); + PatternTextFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); IntervalsSource fuzzyIntervals = ft.fuzzyIntervals("foo", 1, 2, true, MOCK_CONTEXT); assertThat(fuzzyIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); } public void testRangeIntervals() { - MappedFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); + PatternTextFieldType ft = new PatternTextFieldType("field", randomBoolean(), randomBoolean()); IntervalsSource rangeIntervals = ft.rangeIntervals(new BytesRef("foo"), new BytesRef("foo1"), true, true, MOCK_CONTEXT); assertThat(rangeIntervals, Matchers.instanceOf(SourceIntervalsSource.class)); assertEquals(