Skip to content

Commit

Permalink
Flatten SearchService and clean up build-in registration
Browse files Browse the repository at this point in the history
Relates to elastic#12783
  • Loading branch information
s1monw committed Aug 12, 2015
1 parent 3b2f28f commit 6316718
Show file tree
Hide file tree
Showing 33 changed files with 523 additions and 980 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.elasticsearch.node.internal.InternalSettingsPreparer;
import org.elasticsearch.plugins.PluginsModule;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.search.TransportSearchModule;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolModule;
import org.elasticsearch.transport.TransportModule;
Expand Down Expand Up @@ -138,8 +138,13 @@ public TransportClient build() {
modules.add(new NetworkModule());
modules.add(new ClusterNameModule(this.settings));
modules.add(new ThreadPoolModule(threadPool));
modules.add(new TransportSearchModule());
modules.add(new TransportModule(this.settings));
modules.add(new SearchModule(this.settings) {
@Override
protected void configure() {
// noop
}
});
modules.add(new ActionModule(true));
modules.add(new ClientTransportModule());
modules.add(new CircuitBreakerModule(this.settings));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,42 @@

package org.elasticsearch.index.query.functionscore;

import com.google.common.collect.ImmutableMap;

import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.query.functionscore.exp.ExponentialDecayFunctionParser;
import org.elasticsearch.index.query.functionscore.factor.FactorParser;
import org.elasticsearch.index.query.functionscore.fieldvaluefactor.FieldValueFactorFunctionParser;
import org.elasticsearch.index.query.functionscore.gauss.GaussDecayFunctionParser;
import org.elasticsearch.index.query.functionscore.lin.LinearDecayFunctionParser;
import org.elasticsearch.index.query.functionscore.random.RandomScoreFunctionParser;
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionParser;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ScoreFunctionParserMapper {

protected ImmutableMap<String, ScoreFunctionParser> functionParsers;
protected Map<String, ScoreFunctionParser> functionParsers;

@Inject
public ScoreFunctionParserMapper(Set<ScoreFunctionParser> parsers) {
MapBuilder<String, ScoreFunctionParser> builder = MapBuilder.newMapBuilder();
Map<String, ScoreFunctionParser> map = new HashMap<>();
// build-in parsers
addParser(new FactorParser(), map);
addParser(new ScriptScoreFunctionParser(), map);
addParser(new GaussDecayFunctionParser(), map);
addParser(new LinearDecayFunctionParser(), map);
addParser(new ExponentialDecayFunctionParser(), map);
addParser(new RandomScoreFunctionParser(), map);
addParser(new FieldValueFactorFunctionParser(), map);
for (ScoreFunctionParser scoreFunctionParser : parsers) {
for (String name : scoreFunctionParser.getNames()) {
builder.put(name, scoreFunctionParser);
}
addParser(scoreFunctionParser, map);
}
this.functionParsers = builder.immutableMap();
this.functionParsers = Collections.unmodifiableMap(map);
}

public ScoreFunctionParser get(QueryParseContext parseContext, String parserName) {
Expand All @@ -55,4 +69,10 @@ private ScoreFunctionParser get(String parserName) {
return functionParsers.get(parserName);
}

private void addParser(ScoreFunctionParser scoreFunctionParser, Map<String, ScoreFunctionParser> map) {
for (String name : scoreFunctionParser.getNames()) {
map.put(name, scoreFunctionParser);
}
}

}
Loading

0 comments on commit 6316718

Please sign in to comment.