Skip to content

Commit

Permalink
Cut significant_terms to registerAggregation
Browse files Browse the repository at this point in the history
and remove its PROTOTYPE.

Relates to #17085
  • Loading branch information
nik9000 committed Apr 15, 2016
1 parent d223090 commit 65803f8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms;
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.UnmappedSignificantTerms;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser;
Expand Down Expand Up @@ -469,7 +470,9 @@ protected void configureAggs() {
registerAggregation(DiversifiedAggregatorBuilder::new, new DiversifiedSamplerParser(),
DiversifiedAggregatorBuilder.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(DateRangeAggregatorBuilder::new, new DateRangeParser(), DateRangeAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(IPv4RangeAggregatorBuilder::new, new IpRangeParser(), IPv4RangeAggregatorBuilder.AGGREGATION_NAME_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.index.FilterableTermsEnum;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
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.SignificanceHeuristic;
import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicStreams;
Expand All @@ -41,40 +39,80 @@
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;

import java.io.IOException;
import java.util.Objects;

/**
*
*/
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 HEURISTIC = new ParseField("significance_heuristic");

static final TermsAggregator.BucketCountThresholds DEFAULT_BUCKET_COUNT_THRESHOLDS = new TermsAggregator.BucketCountThresholds(
3, 0, 10, -1);

static final SignificantTermsAggregatorBuilder PROTOTYPE = new SignificantTermsAggregatorBuilder("", null);

private IncludeExclude includeExclude = null;
private String executionHint = null;
private String indexedFieldName;
private MappedFieldType fieldType;
private FilterableTermsEnum termsEnum;
private int numberOfAggregatorsCreated = 0;
private QueryBuilder<?> filterBuilder = null;
private TermsAggregator.BucketCountThresholds bucketCountThresholds = new BucketCountThresholds(DEFAULT_BUCKET_COUNT_THRESHOLDS);
private SignificanceHeuristic significanceHeuristic = JLHScore.PROTOTYPE;

protected TermsAggregator.BucketCountThresholds getBucketCountThresholds() {
return new TermsAggregator.BucketCountThresholds(bucketCountThresholds);
}

public SignificantTermsAggregatorBuilder(String name, ValueType 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() {
return bucketCountThresholds;
}
Expand Down Expand Up @@ -217,39 +255,6 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params)
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
protected int innerHashCode() {
return Objects.hash(bucketCountThresholds, executionHint, filterBuilder, includeExclude, significanceHeuristic);
Expand All @@ -264,4 +269,9 @@ protected boolean innerEquals(Object obj) {
&& Objects.equals(includeExclude, other.includeExclude)
&& Objects.equals(significanceHeuristic, other.significanceHeuristic);
}

@Override
public String getWriteableName() {
return NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public SignificantTermsParser(SignificanceHeuristicParserMapper significanceHeur
this.queriesRegistry = queriesRegistry;
}

@Override
public String type() {
return SignificantStringTerms.TYPE.name();
}

@Override
protected SignificantTermsAggregatorBuilder doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType,
ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint,
Expand Down Expand Up @@ -103,11 +98,6 @@ public boolean parseSpecial(String aggregationName, XContentParser parser, Parse
return false;
}

@Override
public SignificantTermsAggregatorBuilder getFactoryPrototypes() {
return SignificantTermsAggregatorBuilder.PROTOTYPE;
}

@Override
protected BucketCountThresholds getDefaultBucketCountThresholds() {
return new TermsAggregator.BucketCountThresholds(SignificantTermsAggregatorBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS);
Expand Down

0 comments on commit 65803f8

Please sign in to comment.