|
@@ -78,9 +78,11 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
|
|
|
return Disjunction.fromXContent(parser);
|
|
|
case "all_of":
|
|
|
return Combine.fromXContent(parser);
|
|
|
+ case "prefix":
|
|
|
+ return Prefix.fromXContent(parser);
|
|
|
}
|
|
|
throw new ParsingException(parser.getTokenLocation(),
|
|
|
- "Unknown interval type [" + parser.currentName() + "], expecting one of [match, any_of, all_of]");
|
|
|
+ "Unknown interval type [" + parser.currentName() + "], expecting one of [match, any_of, all_of, prefix]");
|
|
|
}
|
|
|
|
|
|
private static IntervalsSourceProvider parseInnerIntervals(XContentParser parser) throws IOException {
|
|
@@ -138,10 +140,10 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
|
|
|
if (useField != null) {
|
|
|
fieldType = context.fieldMapper(useField);
|
|
|
assert fieldType != null;
|
|
|
- source = Intervals.fixField(useField, fieldType.intervals(query, maxGaps, ordered, analyzer));
|
|
|
+ source = Intervals.fixField(useField, fieldType.intervals(query, maxGaps, ordered, analyzer, false));
|
|
|
}
|
|
|
else {
|
|
|
- source = fieldType.intervals(query, maxGaps, ordered, analyzer);
|
|
|
+ source = fieldType.intervals(query, maxGaps, ordered, analyzer, false);
|
|
|
}
|
|
|
if (filter != null) {
|
|
|
return filter.filter(source, context, fieldType);
|
|
@@ -440,6 +442,109 @@ public abstract class IntervalsSourceProvider implements NamedWriteable, ToXCont
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static class Prefix extends IntervalsSourceProvider {
|
|
|
+
|
|
|
+ public static final String NAME = "prefix";
|
|
|
+
|
|
|
+ private final String term;
|
|
|
+ private final String analyzer;
|
|
|
+ private final String useField;
|
|
|
+
|
|
|
+ public Prefix(String term, String analyzer, String useField) {
|
|
|
+ this.term = term;
|
|
|
+ this.analyzer = analyzer;
|
|
|
+ this.useField = useField;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Prefix(StreamInput in) throws IOException {
|
|
|
+ this.term = in.readString();
|
|
|
+ this.analyzer = in.readOptionalString();
|
|
|
+ this.useField = in.readOptionalString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IntervalsSource getSource(QueryShardContext context, MappedFieldType fieldType) throws IOException {
|
|
|
+ NamedAnalyzer analyzer = null;
|
|
|
+ if (this.analyzer != null) {
|
|
|
+ analyzer = context.getMapperService().getIndexAnalyzers().get(this.analyzer);
|
|
|
+ }
|
|
|
+ IntervalsSource source;
|
|
|
+ if (useField != null) {
|
|
|
+ fieldType = context.fieldMapper(useField);
|
|
|
+ assert fieldType != null;
|
|
|
+ source = Intervals.fixField(useField, fieldType.intervals(term, 0, false, analyzer, true));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ source = fieldType.intervals(term, 0, false, analyzer, true);
|
|
|
+ }
|
|
|
+ return source;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void extractFields(Set<String> fields) {
|
|
|
+ if (useField != null) {
|
|
|
+ fields.add(useField);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object o) {
|
|
|
+ if (this == o) return true;
|
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
+ Prefix prefix = (Prefix) o;
|
|
|
+ return Objects.equals(term, prefix.term) &&
|
|
|
+ Objects.equals(analyzer, prefix.analyzer) &&
|
|
|
+ Objects.equals(useField, prefix.useField);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return Objects.hash(term, analyzer, useField);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getWriteableName() {
|
|
|
+ return NAME;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void writeTo(StreamOutput out) throws IOException {
|
|
|
+ out.writeString(term);
|
|
|
+ out.writeOptionalString(analyzer);
|
|
|
+ out.writeOptionalString(useField);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
+ builder.startObject(NAME);
|
|
|
+ builder.field("term", term);
|
|
|
+ if (analyzer != null) {
|
|
|
+ builder.field("analyzer", analyzer);
|
|
|
+ }
|
|
|
+ if (useField != null) {
|
|
|
+ builder.field("use_field", useField);
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ return builder;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final ConstructingObjectParser<Prefix, Void> PARSER = new ConstructingObjectParser<>(NAME, args -> {
|
|
|
+ String term = (String) args[0];
|
|
|
+ String analyzer = (String) args[1];
|
|
|
+ String useField = (String) args[2];
|
|
|
+ return new Prefix(term, analyzer, useField);
|
|
|
+ });
|
|
|
+ static {
|
|
|
+ PARSER.declareString(constructorArg(), new ParseField("term"));
|
|
|
+ PARSER.declareString(optionalConstructorArg(), new ParseField("analyzer"));
|
|
|
+ PARSER.declareString(optionalConstructorArg(), new ParseField("use_field"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Prefix fromXContent(XContentParser parser) throws IOException {
|
|
|
+ return PARSER.parse(parser, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static class ScriptFilterSource extends FilteredIntervalsSource {
|
|
|
|
|
|
final IntervalFilterScript script;
|