summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/search/aggregations
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/org/elasticsearch/search/aggregations')
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/SubAggCollectionModeTests.java82
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java45
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsTests.java226
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java232
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java27
5 files changed, 581 insertions, 31 deletions
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/SubAggCollectionModeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/SubAggCollectionModeTests.java
new file mode 100644
index 0000000000..131144dc5d
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/SubAggCollectionModeTests.java
@@ -0,0 +1,82 @@
+/*
+ * 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.search.aggregations;
+
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
+import org.elasticsearch.test.ESTestCase;
+
+import java.io.IOException;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+
+public class SubAggCollectionModeTests extends ESTestCase {
+
+ public void testValidOrdinals() {
+ assertThat(SubAggCollectionMode.DEPTH_FIRST.ordinal(), equalTo(0));
+ assertThat(SubAggCollectionMode.BREADTH_FIRST.ordinal(), equalTo(1));
+ }
+
+ public void testwriteTo() throws Exception {
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ SubAggCollectionMode.DEPTH_FIRST.writeTo(out);
+ try (StreamInput in = StreamInput.wrap(out.bytes())) {
+ assertThat(in.readVInt(), equalTo(0));
+ }
+ }
+
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ SubAggCollectionMode.BREADTH_FIRST.writeTo(out);
+ try (StreamInput in = StreamInput.wrap(out.bytes())) {
+ assertThat(in.readVInt(), equalTo(1));
+ }
+ }
+ }
+
+ public void testReadFrom() throws Exception {
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.writeVInt(0);
+ try (StreamInput in = StreamInput.wrap(out.bytes())) {
+ assertThat(SubAggCollectionMode.BREADTH_FIRST.readFrom(in), equalTo(SubAggCollectionMode.DEPTH_FIRST));
+ }
+ }
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.writeVInt(1);
+ try (StreamInput in = StreamInput.wrap(out.bytes())) {
+ assertThat(SubAggCollectionMode.BREADTH_FIRST.readFrom(in), equalTo(SubAggCollectionMode.BREADTH_FIRST));
+ }
+ }
+ }
+
+ public void testInvalidReadFrom() throws Exception {
+ try (BytesStreamOutput out = new BytesStreamOutput()) {
+ out.writeVInt(randomIntBetween(2, Integer.MAX_VALUE));
+ try (StreamInput in = StreamInput.wrap(out.bytes())) {
+ SubAggCollectionMode.BREADTH_FIRST.readFrom(in);
+ fail("Expected IOException");
+ } catch(IOException e) {
+ assertThat(e.getMessage(), containsString("Unknown SubAggCollectionMode ordinal ["));
+ }
+
+ }
+ }
+}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java
index 6c1e7dfcab..173f9ddfef 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java
@@ -20,6 +20,7 @@ package org.elasticsearch.search.aggregations.bucket;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -52,7 +53,6 @@ import org.elasticsearch.search.aggregations.bucket.significant.heuristics.Signi
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
-import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.search.aggregations.bucket.SharedSignificantTermsTestMethods;
@@ -163,7 +163,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
public static class CustomSignificanceHeuristicPlugin extends Plugin {
static {
- SignificanceHeuristicStreams.registerStream(SimpleHeuristic.STREAM);
+ SignificanceHeuristicStreams.registerPrototype(SimpleHeuristic.PROTOTYPE);
}
@Override
@@ -187,24 +187,30 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
public static class SimpleHeuristic extends SignificanceHeuristic {
- protected static final String[] NAMES = {"simple"};
+ static final SimpleHeuristic PROTOTYPE = new SimpleHeuristic();
- public static final SignificanceHeuristicStreams.Stream STREAM = new SignificanceHeuristicStreams.Stream() {
- @Override
- public SignificanceHeuristic readResult(StreamInput in) throws IOException {
- return readFrom(in);
- }
+ protected static final ParseField NAMES_FIELD = new ParseField("simple");
- @Override
- public String getName() {
- return NAMES[0];
- }
- };
+ @Override
+ public String getWriteableName() {
+ return NAMES_FIELD.getPreferredName();
+ }
- public static SignificanceHeuristic readFrom(StreamInput in) throws IOException {
+ @Override
+ public SignificanceHeuristic readFrom(StreamInput in) throws IOException {
return new SimpleHeuristic();
}
+ @Override
+ public void writeTo(StreamOutput out) throws IOException {
+ }
+
+ @Override
+ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
+ builder.startObject(NAMES_FIELD.getPreferredName()).endObject();
+ return builder;
+ }
+
/**
* @param subsetFreq The frequency of the term in the selected sample
* @param subsetSize The size of the selected sample (typically number of docs)
@@ -217,15 +223,10 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
return subsetFreq / subsetSize > supersetFreq / supersetSize ? 2.0 : 1.0;
}
- @Override
- public void writeTo(StreamOutput out) throws IOException {
- out.writeString(STREAM.getName());
- }
-
public static class SimpleHeuristicParser implements SignificanceHeuristicParser {
@Override
- public SignificanceHeuristic parse(XContentParser parser, ParseFieldMatcher parseFieldMatcher, SearchContext context)
+ public SignificanceHeuristic parse(XContentParser parser, ParseFieldMatcher parseFieldMatcher)
throws IOException, QueryShardException {
parser.nextToken();
return new SimpleHeuristic();
@@ -233,7 +234,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
@Override
public String[] getNames() {
- return NAMES;
+ return NAMES_FIELD.getAllNamesIncludedDeprecated();
}
}
@@ -241,7 +242,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
- builder.startObject(STREAM.getName()).endObject();
+ builder.startObject(NAMES_FIELD.getPreferredName()).endObject();
return builder;
}
}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsTests.java
new file mode 100644
index 0000000000..8ad928e5ed
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsTests.java
@@ -0,0 +1,226 @@
+/*
+ * 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.search.aggregations.bucket;
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.automaton.RegExp;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.script.Script;
+import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
+import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregatorFactory;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.ChiSquare;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.GND;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.MutualInformation;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.PercentageScore;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.ScriptHeuristic;
+import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic;
+import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory.ExecutionMode;
+import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
+import org.elasticsearch.search.aggregations.support.ValuesSourceType;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class SignificantTermsTests extends BaseAggregationTestCase<SignificantTermsAggregatorFactory> {
+
+ private static final String[] executionHints;
+
+ static {
+ ExecutionMode[] executionModes = ExecutionMode.values();
+ executionHints = new String[executionModes.length];
+ for (int i = 0; i < executionModes.length; i++) {
+ executionHints[i] = executionModes[i].toString();
+ }
+ }
+
+ @Override
+ protected SignificantTermsAggregatorFactory createTestAggregatorFactory() {
+ String name = randomAsciiOfLengthBetween(3, 20);
+ SignificantTermsAggregatorFactory factory = new SignificantTermsAggregatorFactory(name, ValuesSourceType.ANY, null);
+ String field = randomAsciiOfLengthBetween(3, 20);
+ int randomFieldBranch = randomInt(2);
+ switch (randomFieldBranch) {
+ case 0:
+ factory.field(field);
+ break;
+ case 1:
+ factory.field(field);
+ factory.script(new Script("_value + 1"));
+ break;
+ case 2:
+ factory.script(new Script("doc[" + field + "] + 1"));
+ break;
+ default:
+ fail();
+ }
+ if (randomBoolean()) {
+ factory.missing("MISSING");
+ }
+ if (randomBoolean()) {
+ int size = randomInt(4);
+ switch (size) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ size = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setRequiredSize(size);
+
+ }
+ if (randomBoolean()) {
+ int shardSize = randomInt(4);
+ switch (shardSize) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ shardSize = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setShardSize(shardSize);
+ }
+ if (randomBoolean()) {
+ int minDocCount = randomInt(4);
+ switch (minDocCount) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ minDocCount = randomInt();
+ break;
+ }
+ factory.bucketCountThresholds().setMinDocCount(minDocCount);
+ }
+ if (randomBoolean()) {
+ int shardMinDocCount = randomInt(4);
+ switch (shardMinDocCount) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ shardMinDocCount = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setShardMinDocCount(shardMinDocCount);
+ }
+ if (randomBoolean()) {
+ factory.executionHint(randomFrom(executionHints));
+ }
+ if (randomBoolean()) {
+ factory.format("###.##");
+ }
+ if (randomBoolean()) {
+ IncludeExclude incExc = null;
+ switch (randomInt(5)) {
+ case 0:
+ incExc = new IncludeExclude(new RegExp("foobar"), null);
+ break;
+ case 1:
+ incExc = new IncludeExclude(null, new RegExp("foobaz"));
+ break;
+ case 2:
+ incExc = new IncludeExclude(new RegExp("foobar"), new RegExp("foobaz"));
+ break;
+ case 3:
+ SortedSet<BytesRef> includeValues = new TreeSet<>();
+ int numIncs = randomIntBetween(1, 20);
+ for (int i = 0; i < numIncs; i++) {
+ includeValues.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ SortedSet<BytesRef> excludeValues = null;
+ incExc = new IncludeExclude(includeValues, excludeValues);
+ break;
+ case 4:
+ SortedSet<BytesRef> includeValues2 = null;
+ SortedSet<BytesRef> excludeValues2 = new TreeSet<>();
+ int numExcs2 = randomIntBetween(1, 20);
+ for (int i = 0; i < numExcs2; i++) {
+ excludeValues2.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ incExc = new IncludeExclude(includeValues2, excludeValues2);
+ break;
+ case 5:
+ SortedSet<BytesRef> includeValues3 = new TreeSet<>();
+ int numIncs3 = randomIntBetween(1, 20);
+ for (int i = 0; i < numIncs3; i++) {
+ includeValues3.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ SortedSet<BytesRef> excludeValues3 = new TreeSet<>();
+ int numExcs3 = randomIntBetween(1, 20);
+ for (int i = 0; i < numExcs3; i++) {
+ excludeValues3.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ incExc = new IncludeExclude(includeValues3, excludeValues3);
+ break;
+ default:
+ fail();
+ }
+ factory.includeExclude(incExc);
+ }
+ if (randomBoolean()) {
+ SignificanceHeuristic significanceHeuristic = null;
+ switch (randomInt(5)) {
+ case 0:
+ significanceHeuristic = PercentageScore.PROTOTYPE;
+ break;
+ case 1:
+ significanceHeuristic = new ChiSquare(randomBoolean(), randomBoolean());
+ break;
+ case 2:
+ significanceHeuristic = new GND(randomBoolean());
+ break;
+ case 3:
+ significanceHeuristic = new MutualInformation(randomBoolean(), randomBoolean());
+ break;
+ case 4:
+ significanceHeuristic = new ScriptHeuristic(new Script("foo"));
+ break;
+ case 5:
+ significanceHeuristic = JLHScore.PROTOTYPE;
+ break;
+ default:
+ fail();
+ }
+ factory.significanceHeuristic(significanceHeuristic);
+ }
+ if (randomBoolean()) {
+ factory.backgroundFilter(QueryBuilders.termsQuery("foo", "bar"));
+ }
+ return factory;
+ }
+
+}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java
new file mode 100644
index 0000000000..fb57b6d1b2
--- /dev/null
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsTests.java
@@ -0,0 +1,232 @@
+/*
+ * 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.search.aggregations.bucket;
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.automaton.RegExp;
+import org.elasticsearch.script.Script;
+import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
+import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
+import org.elasticsearch.search.aggregations.bucket.terms.Terms;
+import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory;
+import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory.ExecutionMode;
+import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude;
+import org.elasticsearch.search.aggregations.support.ValuesSourceType;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class TermsTests extends BaseAggregationTestCase<TermsAggregatorFactory> {
+
+ private static final String[] executionHints;
+
+ static {
+ ExecutionMode[] executionModes = ExecutionMode.values();
+ executionHints = new String[executionModes.length];
+ for (int i = 0; i < executionModes.length; i++) {
+ executionHints[i] = executionModes[i].toString();
+ }
+ }
+
+ @Override
+ protected TermsAggregatorFactory createTestAggregatorFactory() {
+ String name = randomAsciiOfLengthBetween(3, 20);
+ TermsAggregatorFactory factory = new TermsAggregatorFactory(name, ValuesSourceType.ANY, null);
+ String field = randomAsciiOfLengthBetween(3, 20);
+ int randomFieldBranch = randomInt(2);
+ switch (randomFieldBranch) {
+ case 0:
+ factory.field(field);
+ break;
+ case 1:
+ factory.field(field);
+ factory.script(new Script("_value + 1"));
+ break;
+ case 2:
+ factory.script(new Script("doc[" + field + "] + 1"));
+ break;
+ default:
+ fail();
+ }
+ if (randomBoolean()) {
+ factory.missing("MISSING");
+ }
+ if (randomBoolean()) {
+ int size = randomInt(4);
+ switch (size) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ size = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setRequiredSize(size);
+
+ }
+ if (randomBoolean()) {
+ int shardSize = randomInt(4);
+ switch (shardSize) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ shardSize = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setShardSize(shardSize);
+ }
+ if (randomBoolean()) {
+ int minDocCount = randomInt(4);
+ switch (minDocCount) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ minDocCount = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setMinDocCount(minDocCount);
+ }
+ if (randomBoolean()) {
+ int shardMinDocCount = randomInt(4);
+ switch (shardMinDocCount) {
+ case 0:
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ shardMinDocCount = randomInt();
+ break;
+ default:
+ fail();
+ }
+ factory.bucketCountThresholds().setShardMinDocCount(shardMinDocCount);
+ }
+ if (randomBoolean()) {
+ factory.collectMode(randomFrom(SubAggCollectionMode.values()));
+ }
+ if (randomBoolean()) {
+ factory.executionHint(randomFrom(executionHints));
+ }
+ if (randomBoolean()) {
+ factory.format("###.##");
+ }
+ if (randomBoolean()) {
+ IncludeExclude incExc = null;
+ switch (randomInt(5)) {
+ case 0:
+ incExc = new IncludeExclude(new RegExp("foobar"), null);
+ break;
+ case 1:
+ incExc = new IncludeExclude(null, new RegExp("foobaz"));
+ break;
+ case 2:
+ incExc = new IncludeExclude(new RegExp("foobar"), new RegExp("foobaz"));
+ break;
+ case 3:
+ SortedSet<BytesRef> includeValues = new TreeSet<>();
+ int numIncs = randomIntBetween(1, 20);
+ for (int i = 0; i < numIncs; i++) {
+ includeValues.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ SortedSet<BytesRef> excludeValues = null;
+ incExc = new IncludeExclude(includeValues, excludeValues);
+ break;
+ case 4:
+ SortedSet<BytesRef> includeValues2 = null;
+ SortedSet<BytesRef> excludeValues2 = new TreeSet<>();
+ int numExcs2 = randomIntBetween(1, 20);
+ for (int i = 0; i < numExcs2; i++) {
+ excludeValues2.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ incExc = new IncludeExclude(includeValues2, excludeValues2);
+ break;
+ case 5:
+ SortedSet<BytesRef> includeValues3 = new TreeSet<>();
+ int numIncs3 = randomIntBetween(1, 20);
+ for (int i = 0; i < numIncs3; i++) {
+ includeValues3.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ SortedSet<BytesRef> excludeValues3 = new TreeSet<>();
+ int numExcs3 = randomIntBetween(1, 20);
+ for (int i = 0; i < numExcs3; i++) {
+ excludeValues3.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
+ }
+ incExc = new IncludeExclude(includeValues3, excludeValues3);
+ break;
+ default:
+ fail();
+ }
+ factory.includeExclude(incExc);
+ }
+ if (randomBoolean()) {
+ List<Terms.Order> order = randomOrder();
+ factory.order(order);
+ }
+ if (randomBoolean()) {
+ factory.showTermDocCountError(randomBoolean());
+ }
+ return factory;
+ }
+
+ private List<Terms.Order> randomOrder() {
+ List<Terms.Order> orders = new ArrayList<>();
+ switch (randomInt(4)) {
+ case 0:
+ orders.add(Terms.Order.term(randomBoolean()));
+ break;
+ case 1:
+ orders.add(Terms.Order.count(randomBoolean()));
+ break;
+ case 2:
+ orders.add(Terms.Order.aggregation(randomAsciiOfLengthBetween(3, 20), randomBoolean()));
+ break;
+ case 3:
+ orders.add(Terms.Order.aggregation(randomAsciiOfLengthBetween(3, 20), randomAsciiOfLengthBetween(3, 20), randomBoolean()));
+ break;
+ case 4:
+ int numOrders = randomIntBetween(1, 3);
+ for (int i = 0; i < numOrders; i++) {
+ orders.addAll(randomOrder());
+ }
+ break;
+ default:
+ fail();
+ }
+ return orders;
+ }
+
+}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java
index 0fe9113e8f..166efe27a3 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java
@@ -22,11 +22,14 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
+import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
+import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
+import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
@@ -127,7 +130,7 @@ public class SignificanceHeuristicTests extends ESTestCase {
SignificanceHeuristic getRandomSignificanceheuristic() {
List<SignificanceHeuristic> heuristics = new ArrayList<>();
- heuristics.add(JLHScore.INSTANCE);
+ heuristics.add(JLHScore.PROTOTYPE);
heuristics.add(new MutualInformation(randomBoolean(), randomBoolean()));
heuristics.add(new GND(randomBoolean()));
heuristics.add(new ChiSquare(randomBoolean(), randomBoolean()));
@@ -227,11 +230,14 @@ public class SignificanceHeuristicTests extends ESTestCase {
checkParseException(heuristicParserMapper, searchContext, faultyHeuristicdefinition, expectedError);
}
- protected void checkParseException(SignificanceHeuristicParserMapper heuristicParserMapper, SearchContext searchContext, String faultyHeuristicDefinition, String expectedError) throws IOException {
+ protected void checkParseException(SignificanceHeuristicParserMapper heuristicParserMapper, SearchContext searchContext,
+ String faultyHeuristicDefinition, String expectedError) throws IOException {
+
+ IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, new HashSet<>(), new NamedWriteableRegistry());
try {
XContentParser stParser = JsonXContent.jsonXContent.createParser("{\"field\":\"text\", " + faultyHeuristicDefinition + ",\"min_doc_count\":200}");
stParser.nextToken();
- new SignificantTermsParser(heuristicParserMapper).parse("testagg", stParser, searchContext);
+ new SignificantTermsParser(heuristicParserMapper, registry).parse("testagg", stParser, searchContext);
fail();
} catch (ElasticsearchParseException e) {
assertTrue(e.getMessage().contains(expectedError));
@@ -247,9 +253,12 @@ public class SignificanceHeuristicTests extends ESTestCase {
return parseSignificanceHeuristic(heuristicParserMapper, searchContext, stParser);
}
- private SignificanceHeuristic parseSignificanceHeuristic(SignificanceHeuristicParserMapper heuristicParserMapper, SearchContext searchContext, XContentParser stParser) throws IOException {
+ private SignificanceHeuristic parseSignificanceHeuristic(SignificanceHeuristicParserMapper heuristicParserMapper,
+ SearchContext searchContext, XContentParser stParser) throws IOException {
+ IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, new HashSet<>(), new NamedWriteableRegistry());
stParser.nextToken();
- SignificantTermsAggregatorFactory aggregatorFactory = (SignificantTermsAggregatorFactory) new SignificantTermsParser(heuristicParserMapper).parse("testagg", stParser, searchContext);
+ SignificantTermsAggregatorFactory aggregatorFactory = (SignificantTermsAggregatorFactory) new SignificantTermsParser(
+ heuristicParserMapper, registry).parse("testagg", stParser, searchContext);
stParser.nextToken();
assertThat(aggregatorFactory.getBucketCountThresholds().getMinDocCount(), equalTo(200l));
assertThat(stParser.currentToken(), equalTo(null));
@@ -365,14 +374,14 @@ public class SignificanceHeuristicTests extends ESTestCase {
testBackgroundAssertions(new MutualInformation(true, true), new MutualInformation(true, false));
testBackgroundAssertions(new ChiSquare(true, true), new ChiSquare(true, false));
testBackgroundAssertions(new GND(true), new GND(false));
- testAssertions(PercentageScore.INSTANCE);
- testAssertions(JLHScore.INSTANCE);
+ testAssertions(PercentageScore.PROTOTYPE);
+ testAssertions(JLHScore.PROTOTYPE);
}
public void testBasicScoreProperties() {
- basicScoreProperties(JLHScore.INSTANCE, true);
+ basicScoreProperties(JLHScore.PROTOTYPE, true);
basicScoreProperties(new GND(true), true);
- basicScoreProperties(PercentageScore.INSTANCE, true);
+ basicScoreProperties(PercentageScore.PROTOTYPE, true);
basicScoreProperties(new MutualInformation(true, true), false);
basicScoreProperties(new ChiSquare(true, true), false);
}