Skip to content

Commit

Permalink
Aggregations: Significant Terms Heuristics now registered correctly
Browse files Browse the repository at this point in the history
Closes #7840
  • Loading branch information
colings86 committed Sep 24, 2014
1 parent 8ba71bf commit 13b5e32
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/elasticsearch/search/SearchModule.java
Expand Up @@ -27,7 +27,6 @@
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.facet.FacetModule;
Expand All @@ -51,7 +50,7 @@ public class SearchModule extends AbstractModule implements SpawnModules {

@Override
public Iterable<? extends Module> spawnModules() {
return ImmutableList.of(new TransportSearchModule(), new FacetModule(), new HighlightModule(), new SuggestModule(), new FunctionScoreModule(), new AggregationModule(), new SignificantTermsHeuristicModule());
return ImmutableList.of(new TransportSearchModule(), new FacetModule(), new HighlightModule(), new SuggestModule(), new FunctionScoreModule(), new AggregationModule());
}

@Override
Expand Down
Expand Up @@ -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.filter.FilterParser;
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser;
Expand All @@ -34,6 +37,7 @@
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.tophits.TopHitsParser;
import org.elasticsearch.search.aggregations.metrics.avg.AvgParser;
Expand All @@ -53,7 +57,7 @@
/**
* 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();

Expand Down Expand Up @@ -107,4 +111,9 @@ protected void configure() {
bind(AggregationPhase.class).asEagerSingleton();
}

@Override
public Iterable<? extends Module> spawnModules() {
return ImmutableList.of(new SignificantTermsHeuristicModule());
}

}
Expand Up @@ -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.filter.InternalFilter;
import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid;
import org.elasticsearch.search.aggregations.bucket.global.InternalGlobal;
Expand All @@ -34,6 +37,7 @@
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;
Expand All @@ -54,7 +58,7 @@
/**
* 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() {
Expand Down Expand Up @@ -94,4 +98,9 @@ protected void configure() {
InternalTopHits.registerStreams();
InternalGeoBounds.registerStream();
}

@Override
public Iterable<? extends Module> spawnModules() {
return ImmutableList.of(new TransportSignificantTermsHeuristicModule());
}
}
Expand Up @@ -30,16 +30,14 @@
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);
registerParser(JLHScore.JLHScoreParser.class);
registerParser(MutualInformation.MutualInformationParser.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
Expand All @@ -49,8 +47,5 @@ protected void configure() {
parserMapBinder.addBinding().to(clazz);
}
bind(SignificanceHeuristicParserMapper.class);
for (SignificanceHeuristicStreams.Stream stream : streams) {
SignificanceHeuristicStreams.registerStream(stream, stream.getName());
}
}
}
@@ -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());
}
}
}
Expand Up @@ -162,7 +162,11 @@ public String description() {
}

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

Expand Down

0 comments on commit 13b5e32

Please sign in to comment.