Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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() + "]"
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Loading