com.thihy.es.analysis.paoding.dict.DictionariesService Maven / Gradle / Ivy
package com.thihy.es.analysis.paoding.dict;
import java.io.IOException;
import java.util.Map;
import net.paoding.analysis.knife.Dictionaries;
import org.elasticsearch.common.Preconditions;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
public class DictionariesService extends AbstractComponent {
private final Map dictionariesLoaders;
@Inject
public DictionariesService(Settings settings, Map dictionariesLoaders) {
super(settings);
this.dictionariesLoaders = ImmutableMap.copyOf(dictionariesLoaders);
}
public Dictionaries load(String type, DictionariesLoadContext context) throws IOException {
DictionariesLoaderFactory dictionariesLoaderFactory = dictionariesLoaders.get(type);
Preconditions.checkArgument(dictionariesLoaderFactory != null, "The type [{}] does not exist. It should be any of {}.", type,
dictionariesLoaders.keySet());
DictionariesLoader dictionariesLoader = dictionariesLoaderFactory.create(context);
return dictionariesLoader.load();
}
}