Aggregations: Significant Terms Heuristics now registered correctly

Closes #7840
This commit is contained in:
Colin Goodheart-Smithe 2014-09-24 11:20:10 +01:00
parent f2be8d83dc
commit f37815a53b
6 changed files with 81 additions and 15 deletions

View File

@ -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<? extends Module> 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

View File

@ -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<Class<? extends Aggregator.Parser>> parsers = Lists.newArrayList();
@ -113,4 +117,9 @@ public class AggregationModule extends AbstractModule {
bind(AggregationPhase.class).asEagerSingleton();
}
@Override
public Iterable<? extends Module> spawnModules() {
return ImmutableList.of(new SignificantTermsHeuristicModule());
}
}

View File

@ -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<? extends Module> spawnModules() {
return ImmutableList.of(new TransportSignificantTermsHeuristicModule());
}
}

View File

@ -30,18 +30,16 @@ import java.util.List;
public class SignificantTermsHeuristicModule extends AbstractModule {
private List<Class<? extends SignificanceHeuristicParser>> parsers = Lists.newArrayList();
private List<SignificanceHeuristicStreams.Stream> 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<? extends SignificanceHeuristicParser> parser, SignificanceHeuristicStreams.Stream stream) {
public void registerParser(Class<? extends SignificanceHeuristicParser> 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());
}
}
}

View File

@ -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<SignificanceHeuristicStreams.Stream> 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());
}
}
}

View File

@ -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);
}
}