Cut significant_terms to registerAggregation

and remove its PROTOTYPE.

Relates to #17085
This commit is contained in:
Nik Everett 2016-04-15 11:25:11 -04:00
parent d223090d7d
commit 65803f8abd
3 changed files with 60 additions and 57 deletions

View File

@ -142,6 +142,7 @@ import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBui
import org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler; import org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregatorBuilder;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsParser; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsParser;
import org.elasticsearch.search.aggregations.bucket.significant.UnmappedSignificantTerms; import org.elasticsearch.search.aggregations.bucket.significant.UnmappedSignificantTerms;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser;
@ -469,7 +470,9 @@ public class SearchModule extends AbstractModule {
registerAggregation(DiversifiedAggregatorBuilder::new, new DiversifiedSamplerParser(), registerAggregation(DiversifiedAggregatorBuilder::new, new DiversifiedSamplerParser(),
DiversifiedAggregatorBuilder.AGGREGATION_NAME_FIELD); DiversifiedAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(TermsAggregatorBuilder::new, new TermsParser(), TermsAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(TermsAggregatorBuilder::new, new TermsParser(), TermsAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregatorParser(new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry)); registerAggregation(SignificantTermsAggregatorBuilder::new,
new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry),
SignificantTermsAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(RangeAggregatorBuilder::new, new RangeParser(), RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(RangeAggregatorBuilder::new, new RangeParser(), RangeAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(DateRangeAggregatorBuilder::new, new DateRangeParser(), DateRangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(DateRangeAggregatorBuilder::new, new DateRangeParser(), DateRangeAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(IPv4RangeAggregatorBuilder::new, new IpRangeParser(), IPv4RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(IPv4RangeAggregatorBuilder::new, new IpRangeParser(), IPv4RangeAggregatorBuilder.AGGREGATION_NAME_FIELD);

View File

@ -21,12 +21,10 @@ package org.elasticsearch.search.aggregations.bucket.significant;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.index.FilterableTermsEnum;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicStreams; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicStreams;
@ -41,6 +39,7 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuild
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
@ -48,6 +47,8 @@ import java.util.Objects;
* *
*/ */
public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBuilder<ValuesSource, SignificantTermsAggregatorBuilder> { public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBuilder<ValuesSource, SignificantTermsAggregatorBuilder> {
public static final String NAME = SignificantStringTerms.TYPE.name();
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
static final ParseField BACKGROUND_FILTER = new ParseField("background_filter"); static final ParseField BACKGROUND_FILTER = new ParseField("background_filter");
static final ParseField HEURISTIC = new ParseField("significance_heuristic"); static final ParseField HEURISTIC = new ParseField("significance_heuristic");
@ -55,26 +56,63 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui
static final TermsAggregator.BucketCountThresholds DEFAULT_BUCKET_COUNT_THRESHOLDS = new TermsAggregator.BucketCountThresholds( static final TermsAggregator.BucketCountThresholds DEFAULT_BUCKET_COUNT_THRESHOLDS = new TermsAggregator.BucketCountThresholds(
3, 0, 10, -1); 3, 0, 10, -1);
static final SignificantTermsAggregatorBuilder PROTOTYPE = new SignificantTermsAggregatorBuilder("", null);
private IncludeExclude includeExclude = null; private IncludeExclude includeExclude = null;
private String executionHint = null; private String executionHint = null;
private String indexedFieldName;
private MappedFieldType fieldType;
private FilterableTermsEnum termsEnum;
private int numberOfAggregatorsCreated = 0;
private QueryBuilder<?> filterBuilder = null; private QueryBuilder<?> filterBuilder = null;
private TermsAggregator.BucketCountThresholds bucketCountThresholds = new BucketCountThresholds(DEFAULT_BUCKET_COUNT_THRESHOLDS); private TermsAggregator.BucketCountThresholds bucketCountThresholds = new BucketCountThresholds(DEFAULT_BUCKET_COUNT_THRESHOLDS);
private SignificanceHeuristic significanceHeuristic = JLHScore.PROTOTYPE; private SignificanceHeuristic significanceHeuristic = JLHScore.PROTOTYPE;
protected TermsAggregator.BucketCountThresholds getBucketCountThresholds() {
return new TermsAggregator.BucketCountThresholds(bucketCountThresholds);
}
public SignificantTermsAggregatorBuilder(String name, ValueType valueType) { public SignificantTermsAggregatorBuilder(String name, ValueType valueType) {
super(name, SignificantStringTerms.TYPE, ValuesSourceType.ANY, valueType); super(name, SignificantStringTerms.TYPE, ValuesSourceType.ANY, valueType);
} }
/**
* Read from a Stream.
*/
public SignificantTermsAggregatorBuilder(StreamInput in) throws IOException {
super(in, SignificantStringTerms.TYPE, ValuesSourceType.ANY);
bucketCountThresholds = BucketCountThresholds.readFromStream(in);
executionHint = in.readOptionalString();
if (in.readBoolean()) {
filterBuilder = in.readQuery();
}
if (in.readBoolean()) {
includeExclude = IncludeExclude.readFromStream(in);
}
significanceHeuristic = SignificanceHeuristicStreams.read(in);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
bucketCountThresholds.writeTo(out);
out.writeOptionalString(executionHint);
boolean hasfilterBuilder = filterBuilder != null;
out.writeBoolean(hasfilterBuilder);
if (hasfilterBuilder) {
out.writeQuery(filterBuilder);
}
boolean hasIncExc = includeExclude != null;
out.writeBoolean(hasIncExc);
if (hasIncExc) {
includeExclude.writeTo(out);
}
SignificanceHeuristicStreams.writeTo(significanceHeuristic, out);
}
@Override
protected boolean usesNewStyleSerialization() {
return true;
}
@Override
protected boolean serializeTargetValueType() {
return true;
}
protected TermsAggregator.BucketCountThresholds getBucketCountThresholds() {
return new TermsAggregator.BucketCountThresholds(bucketCountThresholds);
}
public TermsAggregator.BucketCountThresholds bucketCountThresholds() { public TermsAggregator.BucketCountThresholds bucketCountThresholds() {
return bucketCountThresholds; return bucketCountThresholds;
} }
@ -217,39 +255,6 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui
return builder; return builder;
} }
@Override
protected SignificantTermsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
SignificantTermsAggregatorBuilder factory = new SignificantTermsAggregatorBuilder(name, targetValueType);
factory.bucketCountThresholds = BucketCountThresholds.readFromStream(in);
factory.executionHint = in.readOptionalString();
if (in.readBoolean()) {
factory.filterBuilder = in.readQuery();
}
if (in.readBoolean()) {
factory.includeExclude = IncludeExclude.readFromStream(in);
}
factory.significanceHeuristic = SignificanceHeuristicStreams.read(in);
return factory;
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
bucketCountThresholds.writeTo(out);
out.writeOptionalString(executionHint);
boolean hasfilterBuilder = filterBuilder != null;
out.writeBoolean(hasfilterBuilder);
if (hasfilterBuilder) {
out.writeQuery(filterBuilder);
}
boolean hasIncExc = includeExclude != null;
out.writeBoolean(hasIncExc);
if (hasIncExc) {
includeExclude.writeTo(out);
}
SignificanceHeuristicStreams.writeTo(significanceHeuristic, out);
}
@Override @Override
protected int innerHashCode() { protected int innerHashCode() {
return Objects.hash(bucketCountThresholds, executionHint, filterBuilder, includeExclude, significanceHeuristic); return Objects.hash(bucketCountThresholds, executionHint, filterBuilder, includeExclude, significanceHeuristic);
@ -264,4 +269,9 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui
&& Objects.equals(includeExclude, other.includeExclude) && Objects.equals(includeExclude, other.includeExclude)
&& Objects.equals(significanceHeuristic, other.significanceHeuristic); && Objects.equals(significanceHeuristic, other.significanceHeuristic);
} }
@Override
public String getWriteableName() {
return NAME;
}
} }

View File

@ -52,11 +52,6 @@ public class SignificantTermsParser extends AbstractTermsParser {
this.queriesRegistry = queriesRegistry; this.queriesRegistry = queriesRegistry;
} }
@Override
public String type() {
return SignificantStringTerms.TYPE.name();
}
@Override @Override
protected SignificantTermsAggregatorBuilder doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType, protected SignificantTermsAggregatorBuilder doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint, ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint,
@ -103,11 +98,6 @@ public class SignificantTermsParser extends AbstractTermsParser {
return false; return false;
} }
@Override
public SignificantTermsAggregatorBuilder getFactoryPrototypes() {
return SignificantTermsAggregatorBuilder.PROTOTYPE;
}
@Override @Override
protected BucketCountThresholds getDefaultBucketCountThresholds() { protected BucketCountThresholds getDefaultBucketCountThresholds() {
return new TermsAggregator.BucketCountThresholds(SignificantTermsAggregatorBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS); return new TermsAggregator.BucketCountThresholds(SignificantTermsAggregatorBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS);