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 @@ -246,6 +246,30 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
public static Match fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

String getQuery() {
return query;
}

int getMaxGaps() {
return maxGaps;
}

boolean isOrdered() {
return ordered;
}

String getAnalyzer() {
return analyzer;
}

IntervalFilter getFilter() {
return filter;
}

String getUseField() {
return useField;
}
}

public static class Disjunction extends IntervalsSourceProvider {
Expand Down Expand Up @@ -290,12 +314,13 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Disjunction that = (Disjunction) o;
return Objects.equals(subSources, that.subSources);
return Objects.equals(subSources, that.subSources) &&
Objects.equals(filter, that.filter);
}

@Override
public int hashCode() {
return Objects.hash(subSources);
return Objects.hash(subSources, filter);
}

@Override
Expand Down Expand Up @@ -342,6 +367,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
public static Disjunction fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

List<IntervalsSourceProvider> getSubSources() {
return subSources;
}

IntervalFilter getFilter() {
return filter;
}
}

public static class Combine extends IntervalsSourceProvider {
Expand Down Expand Up @@ -393,12 +426,14 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Combine combine = (Combine) o;
return Objects.equals(subSources, combine.subSources) &&
ordered == combine.ordered && maxGaps == combine.maxGaps;
ordered == combine.ordered &&
maxGaps == combine.maxGaps &&
Objects.equals(filter, combine.filter);
}

@Override
public int hashCode() {
return Objects.hash(subSources, ordered, maxGaps);
return Objects.hash(subSources, ordered, maxGaps, filter);
}

@Override
Expand Down Expand Up @@ -452,6 +487,22 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
public static Combine fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

List<IntervalsSourceProvider> getSubSources() {
return subSources;
}

boolean isOrdered() {
return ordered;
}

int getMaxGaps() {
return maxGaps;
}

IntervalFilter getFilter() {
return filter;
}
}

public static class Prefix extends IntervalsSourceProvider {
Expand Down Expand Up @@ -838,6 +889,30 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
public static Fuzzy fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}

String getTerm() {
return term;
}

int getPrefixLength() {
return prefixLength;
}

boolean isTranspositions() {
return transpositions;
}

Fuzziness getFuzziness() {
return fuzziness;
}

String getAnalyzer() {
return analyzer;
}

String getUseField() {
return useField;
}
}

static class ScriptFilterSource extends FilteredIntervalsSource {
Expand Down Expand Up @@ -985,6 +1060,18 @@ public static IntervalFilter fromXContent(XContentParser parser) throws IOExcept
}
return new IntervalFilter(intervals, type);
}

String getType() {
return type;
}

IntervalsSourceProvider getFilter() {
return filter;
}

Script getScript() {
return script;
}
}


Expand Down
30 changes: 18 additions & 12 deletions server/src/main/java/org/elasticsearch/search/SearchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,18 +794,24 @@ private void registerQueryParsers(List<SearchPlugin> plugins) {
}

private void registerIntervalsSourceProviders() {
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Match.NAME, IntervalsSourceProvider.Match::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Combine.NAME, IntervalsSourceProvider.Combine::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Disjunction.NAME, IntervalsSourceProvider.Disjunction::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Prefix.NAME, IntervalsSourceProvider.Prefix::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Wildcard.NAME, IntervalsSourceProvider.Wildcard::new));
namedWriteables.add(new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Fuzzy.NAME, IntervalsSourceProvider.Fuzzy::new));
namedWriteables.addAll(getIntervalsSourceProviderNamedWritables());
}

public static List<NamedWriteableRegistry.Entry> getIntervalsSourceProviderNamedWritables() {
return List.of(
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Match.NAME, IntervalsSourceProvider.Match::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Combine.NAME, IntervalsSourceProvider.Combine::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Disjunction.NAME, IntervalsSourceProvider.Disjunction::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Prefix.NAME, IntervalsSourceProvider.Prefix::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Wildcard.NAME, IntervalsSourceProvider.Wildcard::new),
new NamedWriteableRegistry.Entry(IntervalsSourceProvider.class,
IntervalsSourceProvider.Fuzzy.NAME, IntervalsSourceProvider.Fuzzy::new)
);
}

private void registerQuery(QuerySpec<?> spec) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.index.query;

import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractSerializingTestCase;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.index.query.IntervalsSourceProvider.Combine;

public class CombineIntervalsSourceProviderTests extends AbstractSerializingTestCase<Combine> {

@Override
protected Combine createTestInstance() {
return IntervalQueryBuilderTests.createRandomCombine(0, randomBoolean());
}

@Override
protected Combine mutateInstance(Combine instance) throws IOException {
List<IntervalsSourceProvider> subSources = instance.getSubSources();
boolean ordered = instance.isOrdered();
int maxGaps = instance.getMaxGaps();
IntervalsSourceProvider.IntervalFilter filter = instance.getFilter();
switch (between(0, 3)) {
case 0:
subSources = subSources == null ?
IntervalQueryBuilderTests.createRandomSourceList(0, randomBoolean(), randomInt(5) + 1) :
null;
break;
case 1:
ordered = !ordered;
break;
case 2:
maxGaps++;
break;
case 3:
filter = filter == null ?
IntervalQueryBuilderTests.createRandomNonNullFilter(0, randomBoolean()) :
FilterIntervalsSourceProviderTests.mutateFilter(filter);
break;
default:
throw new AssertionError("Illegal randomisation branch");
}
return new Combine(subSources, ordered, maxGaps, filter);
}

@Override
protected Writeable.Reader<Combine> instanceReader() {
return Combine::new;
}

@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(SearchModule.getIntervalsSourceProviderNamedWritables());
}

@Override
protected Combine doParseInstance(XContentParser parser) throws IOException {
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
Combine combine = (Combine) IntervalsSourceProvider.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
return combine;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.index.query;

import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.AbstractSerializingTestCase;

import java.io.IOException;
import java.util.List;

import static org.elasticsearch.index.query.IntervalsSourceProvider.Disjunction;

public class DisjunctionIntervalsSourceProviderTests extends AbstractSerializingTestCase<Disjunction> {

@Override
protected Disjunction createTestInstance() {
return IntervalQueryBuilderTests.createRandomDisjunction(0, randomBoolean());
}

@Override
protected Disjunction mutateInstance(Disjunction instance) throws IOException {
List<IntervalsSourceProvider> subSources = instance.getSubSources();
IntervalsSourceProvider.IntervalFilter filter = instance.getFilter();
if (randomBoolean()) {
subSources = subSources == null ?
IntervalQueryBuilderTests.createRandomSourceList(0, randomBoolean(), randomInt(5) + 1) :
null;
} else {
filter = filter == null ?
IntervalQueryBuilderTests.createRandomNonNullFilter(0, randomBoolean()) :
FilterIntervalsSourceProviderTests.mutateFilter(filter);
}
return new Disjunction(subSources, filter);
}

@Override
protected Writeable.Reader<Disjunction> instanceReader() {
return Disjunction::new;
}

@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(SearchModule.getIntervalsSourceProviderNamedWritables());
}

@Override
protected Disjunction doParseInstance(XContentParser parser) throws IOException {
if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
parser.nextToken();
}
Disjunction disjunction = (Disjunction) IntervalsSourceProvider.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
return disjunction;
}
}
Loading