diff options
Diffstat (limited to 'core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java')
-rw-r--r-- | core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java | 45 |
1 files changed, 23 insertions, 22 deletions
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; } } |