Skip to content

Commit 271e9f1

Browse files
Merge branch 'main' into release-notes-9-1-5
2 parents b2ea69f + ac79d0c commit 271e9f1

File tree

10 files changed

+135
-161
lines changed

10 files changed

+135
-161
lines changed

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ public void testPhrasePrefixQuery() throws IOException {
173173
}
174174

175175
public void testTermIntervals() {
176-
MappedFieldType ft = new MatchOnlyTextFieldType("field");
176+
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field");
177177
IntervalsSource termIntervals = ft.termIntervals(new BytesRef("foo"), MOCK_CONTEXT);
178178
assertThat(termIntervals, Matchers.instanceOf(SourceIntervalsSource.class));
179179
assertEquals(Intervals.term(new BytesRef("foo")), ((SourceIntervalsSource) termIntervals).getIntervalsSource());
180180
}
181181

182182
public void testPrefixIntervals() {
183-
MappedFieldType ft = new MatchOnlyTextFieldType("field");
183+
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field");
184184
IntervalsSource prefixIntervals = ft.prefixIntervals(new BytesRef("foo"), MOCK_CONTEXT);
185185
assertThat(prefixIntervals, Matchers.instanceOf(SourceIntervalsSource.class));
186186
assertEquals(
@@ -190,7 +190,7 @@ public void testPrefixIntervals() {
190190
}
191191

192192
public void testWildcardIntervals() {
193-
MappedFieldType ft = new MatchOnlyTextFieldType("field");
193+
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field");
194194
IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT);
195195
assertThat(wildcardIntervals, Matchers.instanceOf(SourceIntervalsSource.class));
196196
assertEquals(
@@ -200,7 +200,7 @@ public void testWildcardIntervals() {
200200
}
201201

202202
public void testRegexpIntervals() {
203-
MappedFieldType ft = new MatchOnlyTextFieldType("field");
203+
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field");
204204
IntervalsSource regexpIntervals = ft.regexpIntervals(new BytesRef("foo"), MOCK_CONTEXT);
205205
assertThat(regexpIntervals, Matchers.instanceOf(SourceIntervalsSource.class));
206206
assertEquals(
@@ -210,13 +210,13 @@ public void testRegexpIntervals() {
210210
}
211211

212212
public void testFuzzyIntervals() {
213-
MappedFieldType ft = new MatchOnlyTextFieldType("field");
213+
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field");
214214
IntervalsSource fuzzyIntervals = ft.fuzzyIntervals("foo", 1, 2, true, MOCK_CONTEXT);
215215
assertThat(fuzzyIntervals, Matchers.instanceOf(SourceIntervalsSource.class));
216216
}
217217

218218
public void testRangeIntervals() {
219-
MappedFieldType ft = new MatchOnlyTextFieldType("field");
219+
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType("field");
220220
IntervalsSource rangeIntervals = ft.rangeIntervals(new BytesRef("foo"), new BytesRef("foo1"), true, true, MOCK_CONTEXT);
221221
assertThat(rangeIntervals, Matchers.instanceOf(SourceIntervalsSource.class));
222222
assertEquals(

plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldTypeTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.index.mapper.FieldTypeTestCase;
1717
import org.elasticsearch.index.mapper.MappedFieldType;
1818
import org.elasticsearch.index.mapper.MapperBuilderContext;
19+
import org.elasticsearch.index.mapper.TextFamilyFieldType;
1920

2021
import java.io.IOException;
2122
import java.util.Collections;
@@ -24,7 +25,7 @@
2425
public class AnnotatedTextFieldTypeTests extends FieldTypeTestCase {
2526

2627
public void testIntervals() throws IOException {
27-
MappedFieldType ft = new AnnotatedTextFieldMapper.AnnotatedTextFieldType("field", Collections.emptyMap());
28+
TextFamilyFieldType ft = new AnnotatedTextFieldMapper.AnnotatedTextFieldType("field", Collections.emptyMap());
2829
IntervalsSource source = ft.termIntervals(new BytesRef("donald"), null);
2930
assertEquals(Intervals.term("donald"), source);
3031
}

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.apache.lucene.index.IndexReader;
1515
import org.apache.lucene.index.Term;
1616
import org.apache.lucene.index.TermsEnum;
17-
import org.apache.lucene.queries.intervals.IntervalsSource;
1817
import org.apache.lucene.queries.spans.SpanMultiTermQueryWrapper;
1918
import org.apache.lucene.queries.spans.SpanQuery;
2019
import org.apache.lucene.search.BooleanClause.Occur;
@@ -24,7 +23,6 @@
2423
import org.apache.lucene.search.MultiTermQuery;
2524
import org.apache.lucene.search.Query;
2625
import org.apache.lucene.search.TermQuery;
27-
import org.apache.lucene.util.BytesRef;
2826
import org.apache.lucene.util.automaton.Automaton;
2927
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
3028
import org.elasticsearch.ElasticsearchException;
@@ -438,72 +436,6 @@ public Query distanceFeatureQuery(Object origin, String pivot, SearchExecutionCo
438436
);
439437
}
440438

441-
/**
442-
* Create an {@link IntervalsSource} for the given term.
443-
*/
444-
public IntervalsSource termIntervals(BytesRef term, SearchExecutionContext context) {
445-
throw new IllegalArgumentException(
446-
"Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]"
447-
);
448-
}
449-
450-
/**
451-
* Create an {@link IntervalsSource} for the given prefix.
452-
*/
453-
public IntervalsSource prefixIntervals(BytesRef prefix, SearchExecutionContext context) {
454-
throw new IllegalArgumentException(
455-
"Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]"
456-
);
457-
}
458-
459-
/**
460-
* Create a fuzzy {@link IntervalsSource} for the given term.
461-
*/
462-
public IntervalsSource fuzzyIntervals(
463-
String term,
464-
int maxDistance,
465-
int prefixLength,
466-
boolean transpositions,
467-
SearchExecutionContext context
468-
) {
469-
throw new IllegalArgumentException(
470-
"Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]"
471-
);
472-
}
473-
474-
/**
475-
* Create a wildcard {@link IntervalsSource} for the given pattern.
476-
*/
477-
public IntervalsSource wildcardIntervals(BytesRef pattern, SearchExecutionContext context) {
478-
throw new IllegalArgumentException(
479-
"Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]"
480-
);
481-
}
482-
483-
/**
484-
* Create a regexp {@link IntervalsSource} for the given pattern.
485-
*/
486-
public IntervalsSource regexpIntervals(BytesRef pattern, SearchExecutionContext context) {
487-
throw new IllegalArgumentException(
488-
"Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]"
489-
);
490-
}
491-
492-
/**
493-
* Create a range {@link IntervalsSource} for the given ranges
494-
*/
495-
public IntervalsSource rangeIntervals(
496-
BytesRef lowerTerm,
497-
BytesRef upperTerm,
498-
boolean includeLower,
499-
boolean includeUpper,
500-
SearchExecutionContext context
501-
) {
502-
throw new IllegalArgumentException(
503-
"Can only use interval queries on text fields - not on [" + name + "] which is of type [" + typeName() + "]"
504-
);
505-
}
506-
507439
/**
508440
* An enum used to describe the relation between the range of terms in a
509441
* shard when compared with a query range

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
package org.elasticsearch.index.mapper;
1111

1212
import org.apache.lucene.analysis.TokenStream;
13-
import org.apache.lucene.queries.intervals.IntervalsSource;
1413
import org.apache.lucene.queries.spans.SpanMultiTermQueryWrapper;
1514
import org.apache.lucene.queries.spans.SpanQuery;
1615
import org.apache.lucene.search.MultiTermQuery;
1716
import org.apache.lucene.search.Query;
18-
import org.apache.lucene.util.BytesRef;
1917
import org.elasticsearch.common.geo.ShapeRelation;
2018
import org.elasticsearch.common.time.DateMathParser;
2119
import org.elasticsearch.common.unit.Fuzziness;
@@ -222,48 +220,6 @@ public Query distanceFeatureQuery(Object origin, String pivot, SearchExecutionCo
222220
throw new QueryShardException(context, fail("distance feature query"));
223221
}
224222

225-
@Override
226-
public IntervalsSource termIntervals(BytesRef term, SearchExecutionContext context) {
227-
throw new QueryShardException(context, fail("term intervals query"));
228-
}
229-
230-
@Override
231-
public IntervalsSource prefixIntervals(BytesRef prefix, SearchExecutionContext context) {
232-
throw new QueryShardException(context, fail("term intervals query"));
233-
}
234-
235-
@Override
236-
public IntervalsSource fuzzyIntervals(
237-
String term,
238-
int maxDistance,
239-
int prefixLength,
240-
boolean transpositions,
241-
SearchExecutionContext context
242-
) {
243-
throw new QueryShardException(context, fail("fuzzy intervals query"));
244-
}
245-
246-
@Override
247-
public IntervalsSource wildcardIntervals(BytesRef pattern, SearchExecutionContext context) {
248-
throw new QueryShardException(context, fail("wildcard intervals query"));
249-
}
250-
251-
@Override
252-
public IntervalsSource regexpIntervals(BytesRef pattern, SearchExecutionContext context) {
253-
throw new QueryShardException(context, fail("regexp intervals query"));
254-
}
255-
256-
@Override
257-
public IntervalsSource rangeIntervals(
258-
BytesRef lowerTerm,
259-
BytesRef upperTerm,
260-
boolean includeLower,
261-
boolean includeUpper,
262-
SearchExecutionContext context
263-
) {
264-
throw new QueryShardException(context, fail("range intervals query"));
265-
}
266-
267223
@Override
268224
public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext) {
269225
throw new IllegalArgumentException(fail("aggregation or sorts"));

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
package org.elasticsearch.index.mapper;
1111

12+
import org.apache.lucene.queries.intervals.IntervalsSource;
13+
import org.apache.lucene.util.BytesRef;
14+
import org.elasticsearch.index.query.SearchExecutionContext;
15+
1216
import java.util.Map;
1317

1418
/**
@@ -50,4 +54,70 @@ public String syntheticSourceFallbackFieldName() {
5054
return isSyntheticSourceEnabled ? name() + "._original" : null;
5155
}
5256

57+
/**
58+
* Create an {@link IntervalsSource} for the given term.
59+
*/
60+
public IntervalsSource termIntervals(BytesRef term, SearchExecutionContext context) {
61+
throw new IllegalArgumentException(
62+
"Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]"
63+
);
64+
}
65+
66+
/**
67+
* Create an {@link IntervalsSource} for the given prefix.
68+
*/
69+
public IntervalsSource prefixIntervals(BytesRef prefix, SearchExecutionContext context) {
70+
throw new IllegalArgumentException(
71+
"Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]"
72+
);
73+
}
74+
75+
/**
76+
* Create a fuzzy {@link IntervalsSource} for the given term.
77+
*/
78+
public IntervalsSource fuzzyIntervals(
79+
String term,
80+
int maxDistance,
81+
int prefixLength,
82+
boolean transpositions,
83+
SearchExecutionContext context
84+
) {
85+
throw new IllegalArgumentException(
86+
"Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]"
87+
);
88+
}
89+
90+
/**
91+
* Create a wildcard {@link IntervalsSource} for the given pattern.
92+
*/
93+
public IntervalsSource wildcardIntervals(BytesRef pattern, SearchExecutionContext context) {
94+
throw new IllegalArgumentException(
95+
"Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]"
96+
);
97+
}
98+
99+
/**
100+
* Create a regexp {@link IntervalsSource} for the given pattern.
101+
*/
102+
public IntervalsSource regexpIntervals(BytesRef pattern, SearchExecutionContext context) {
103+
throw new IllegalArgumentException(
104+
"Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]"
105+
);
106+
}
107+
108+
/**
109+
* Create a range {@link IntervalsSource} for the given ranges
110+
*/
111+
public IntervalsSource rangeIntervals(
112+
BytesRef lowerTerm,
113+
BytesRef upperTerm,
114+
boolean includeLower,
115+
boolean includeUpper,
116+
SearchExecutionContext context
117+
) {
118+
throw new IllegalArgumentException(
119+
"Can only use interval queries on text fields - not on [" + name() + "] which is of type [" + typeName() + "]"
120+
);
121+
}
122+
53123
}

server/src/main/java/org/elasticsearch/index/query/IntervalQueryBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.io.stream.StreamInput;
1818
import org.elasticsearch.common.io.stream.StreamOutput;
1919
import org.elasticsearch.index.mapper.MappedFieldType;
20+
import org.elasticsearch.index.mapper.TextFamilyFieldType;
2021
import org.elasticsearch.xcontent.XContentBuilder;
2122
import org.elasticsearch.xcontent.XContentParser;
2223

@@ -133,7 +134,12 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {
133134
return new MatchNoDocsQuery();
134135
}
135136
}
136-
return new IntervalQuery(field, sourceProvider.getSource(context, fieldType));
137+
if (fieldType instanceof TextFamilyFieldType tfft) {
138+
return new IntervalQuery(field, sourceProvider.getSource(context, tfft));
139+
}
140+
throw new IllegalArgumentException(
141+
"Can only use interval queries on text fields - not on [" + field + "] which is of type [" + fieldType.typeName() + "]"
142+
);
137143
}
138144

139145
@Override

0 commit comments

Comments
 (0)