diff --git a/src/main/java/org/elasticsearch/search/SearchModule.java b/src/main/java/org/elasticsearch/search/SearchModule.java index 04982302e84..7f20317e449 100644 --- a/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/src/main/java/org/elasticsearch/search/SearchModule.java @@ -27,7 +27,6 @@ import org.elasticsearch.index.query.functionscore.FunctionScoreModule; import org.elasticsearch.index.search.morelikethis.MoreLikeThisFetchService; import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.search.aggregations.AggregationModule; -import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificantTermsHeuristicModule; import org.elasticsearch.search.controller.SearchPhaseController; import org.elasticsearch.search.dfs.DfsPhase; import org.elasticsearch.search.fetch.FetchPhase; @@ -50,7 +49,7 @@ public class SearchModule extends AbstractModule implements SpawnModules { @Override public Iterable spawnModules() { - return ImmutableList.of(new TransportSearchModule(), new HighlightModule(), new SuggestModule(), new FunctionScoreModule(), new AggregationModule(), new SignificantTermsHeuristicModule()); + return ImmutableList.of(new TransportSearchModule(), new HighlightModule(), new SuggestModule(), new FunctionScoreModule(), new AggregationModule()); } @Override diff --git a/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java b/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java index d4dd892aae9..2feaf112104 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java +++ b/src/main/java/org/elasticsearch/search/aggregations/AggregationModule.java @@ -18,8 +18,11 @@ */ package org.elasticsearch.search.aggregations; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.search.aggregations.bucket.children.ChildrenParser; import org.elasticsearch.search.aggregations.bucket.filter.FilterParser; @@ -36,6 +39,7 @@ import org.elasticsearch.search.aggregations.bucket.range.date.DateRangeParser; import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser; import org.elasticsearch.search.aggregations.bucket.range.ipv4.IpRangeParser; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsParser; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificantTermsHeuristicModule; import org.elasticsearch.search.aggregations.bucket.terms.TermsParser; import org.elasticsearch.search.aggregations.metrics.avg.AvgParser; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityParser; @@ -56,7 +60,7 @@ import java.util.List; /** * The main module for the get (binding all get components together) */ -public class AggregationModule extends AbstractModule { +public class AggregationModule extends AbstractModule implements SpawnModules{ private List> parsers = Lists.newArrayList(); @@ -113,4 +117,9 @@ public class AggregationModule extends AbstractModule { bind(AggregationPhase.class).asEagerSingleton(); } + @Override + public Iterable spawnModules() { + return ImmutableList.of(new SignificantTermsHeuristicModule()); + } + } diff --git a/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java b/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java index 2acefc854d7..52793f9bbfd 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java +++ b/src/main/java/org/elasticsearch/search/aggregations/TransportAggregationModule.java @@ -18,7 +18,10 @@ */ package org.elasticsearch.search.aggregations; +import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.search.aggregations.bucket.children.InternalChildren; import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters; @@ -36,6 +39,7 @@ import org.elasticsearch.search.aggregations.bucket.range.ipv4.InternalIPv4Range import org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms; import org.elasticsearch.search.aggregations.bucket.significant.UnmappedSignificantTerms; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.TransportSignificantTermsHeuristicModule; import org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms; import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; @@ -57,7 +61,7 @@ import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCou /** * A module that registers all the transport streams for the addAggregation */ -public class TransportAggregationModule extends AbstractModule { +public class TransportAggregationModule extends AbstractModule implements SpawnModules { @Override protected void configure() { @@ -100,4 +104,9 @@ public class TransportAggregationModule extends AbstractModule { InternalGeoBounds.registerStream(); InternalChildren.registerStream(); } + + @Override + public Iterable spawnModules() { + return ImmutableList.of(new TransportSignificantTermsHeuristicModule()); + } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/SignificantTermsHeuristicModule.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/SignificantTermsHeuristicModule.java index 1c195edb54d..b17f502775c 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/SignificantTermsHeuristicModule.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/SignificantTermsHeuristicModule.java @@ -30,18 +30,16 @@ import java.util.List; public class SignificantTermsHeuristicModule extends AbstractModule { private List> parsers = Lists.newArrayList(); - private List streams = Lists.newArrayList(); public SignificantTermsHeuristicModule() { - registerHeuristic(JLHScore.JLHScoreParser.class, JLHScore.STREAM); - registerHeuristic(MutualInformation.MutualInformationParser.class, MutualInformation.STREAM); - registerHeuristic(GND.GNDParser.class, GND.STREAM); - registerHeuristic(ChiSquare.ChiSquareParser.class, ChiSquare.STREAM); + registerParser(JLHScore.JLHScoreParser.class); + registerParser(MutualInformation.MutualInformationParser.class); + registerParser(GND.GNDParser.class); + registerParser(ChiSquare.ChiSquareParser.class); } - public void registerHeuristic(Class parser, SignificanceHeuristicStreams.Stream stream) { + public void registerParser(Class parser) { parsers.add(parser); - streams.add(stream); } @Override @@ -51,8 +49,5 @@ public class SignificantTermsHeuristicModule extends AbstractModule { parserMapBinder.addBinding().to(clazz); } bind(SignificanceHeuristicParserMapper.class); - for (SignificanceHeuristicStreams.Stream stream : streams) { - SignificanceHeuristicStreams.registerStream(stream, stream.getName()); - } } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/TransportSignificantTermsHeuristicModule.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/TransportSignificantTermsHeuristicModule.java new file mode 100644 index 00000000000..efe1d314473 --- /dev/null +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/heuristics/TransportSignificantTermsHeuristicModule.java @@ -0,0 +1,50 @@ +/* + * 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.significant.heuristics; + +import com.google.common.collect.Lists; +import org.elasticsearch.common.inject.AbstractModule; + +import java.util.List; + + +public class TransportSignificantTermsHeuristicModule extends AbstractModule { + + private List streams = Lists.newArrayList(); + + public TransportSignificantTermsHeuristicModule() { + registerStream(JLHScore.STREAM); + registerStream(MutualInformation.STREAM); + registerStream(GND.STREAM); + registerStream(ChiSquare.STREAM); + } + + public void registerStream(SignificanceHeuristicStreams.Stream stream) { + streams.add(stream); + } + + @Override + protected void configure() { + for (SignificanceHeuristicStreams.Stream stream : streams) { + SignificanceHeuristicStreams.registerStream(stream, stream.getName()); + } + } +} diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java index 1d0b58aacce..16d89b016e9 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java @@ -159,7 +159,11 @@ public class SignificantTermsSignificanceScoreTests extends ElasticsearchIntegra } public void onModule(SignificantTermsHeuristicModule significanceModule) { - significanceModule.registerHeuristic(SimpleHeuristic.SimpleHeuristicParser.class, SimpleHeuristic.STREAM); + significanceModule.registerParser(SimpleHeuristic.SimpleHeuristicParser.class); + } + + public void onModule(TransportSignificantTermsHeuristicModule significanceModule) { + significanceModule.registerStream(SimpleHeuristic.STREAM); } }