org.elasticsearch.index.analysis.AnalysisModule Java Examples

The following examples show how to use org.elasticsearch.index.analysis.AnalysisModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IkESPluginTest.java    From es-ik with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultsIcuAnalysis() {
    Index index = new Index("test");

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("path.home", "none")
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();

    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(ImmutableSettings.EMPTY), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, settings),
            new IndexNameModule(index),
            new AnalysisModule(ImmutableSettings.EMPTY, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IKAnalysisBinderProcessor()))
            .createChildInjector(parentInjector);

    AnalysisService analysisService = injector.getInstance(AnalysisService.class);

    TokenizerFactory tokenizerFactory = analysisService.tokenizer("ik_tokenizer");
    MatcherAssert.assertThat(tokenizerFactory, instanceOf(IKTokenizerFactory.class));


}
 
Example #2
Source File: MapperTestUtils.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static AnalysisService newAnalysisService(Settings indexSettings) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Index index = new Index("test");
    Injector injector = new ModulesBuilder().add(
        new IndexSettingsModule(index, indexSettings),
        new IndexNameModule(index),
        new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

    return injector.getInstance(AnalysisService.class);
}
 
Example #3
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static AnalysisService newAnalysisService(Settings indexSettings) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Index index = new Index("test");
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

    return injector.getInstance(AnalysisService.class);
}
 
Example #4
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static MapperService newMapperService(Settings settings, Client client) {
    Settings indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .put(settings)
            .build();
    Index index = new Index("test");
    Injector parentInjector = new ModulesBuilder()
            .add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings)))
            .createInjector();
    AnalysisModule analysisModule = new AnalysisModule(indexSettings,
            parentInjector.getInstance(IndicesAnalysisService.class));
    new AnalysisBaseformPlugin(settings).onModule(analysisModule);
    Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            analysisModule)
            .createChildInjector(parentInjector);
    AnalysisService analysisService = injector.getInstance(AnalysisService.class);
    SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings);
    Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers();
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers();
    MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers);
    return new MapperService(new Index("test"),
            indexSettings,
            analysisService,
            similarityLookupService,
            null,
            mapperRegistry);
}
 
Example #5
Source File: AnalysisBosonNLPPlugin.java    From elasticsearch-analysis-bosonnlp with Apache License 2.0 4 votes vote down vote up
public void onModule(AnalysisModule module) {
    module.addProcessor(new BosonNLPAnalysisBinderProcessor());
}
 
Example #6
Source File: AnalysisIKPlugin.java    From es-ik with Apache License 2.0 4 votes vote down vote up
@Override public void processModule(Module module) {
    if (module instanceof AnalysisModule) {
        AnalysisModule analysisModule = (AnalysisModule) module;
        analysisModule.addProcessor(new IKAnalysisBinderProcessor());
    }
}
 
Example #7
Source File: AnalysisHanLpPlugin.java    From elasticsearch-analysis-hanlp with Apache License 2.0 4 votes vote down vote up
/**
 * Automatically called with the analysis module.
 */
public void onModule(AnalysisModule module) {
    module.addProcessor(new HanLpAnalysisBinderProcessor());
}
 
Example #8
Source File: AnnotationAnalysisPlugin.java    From elasticsearch-analysis-annotation with Apache License 2.0 4 votes vote down vote up
public void onModule(AnalysisModule module) {
    module.addProcessor(new AnnotationAnalysisBinderProcessor());
}
 
Example #9
Source File: AnalysisBaseformPlugin.java    From elasticsearch-analysis-baseform with Apache License 2.0 4 votes vote down vote up
public void onModule(AnalysisModule module) {
    if (settings.getAsBoolean("plugins.baseform.enabled", true)) {
        module.addProcessor(new BaseformAnalysisBinderProcessor());
    }
}
 
Example #10
Source File: AnalysisMeCabKoStandardPlugin.java    From mecab-ko-lucene-analyzer with Apache License 2.0 4 votes vote down vote up
public void onModule(AnalysisModule module) {
  module.addTokenizer(
      "mecab_ko_standard_tokenizer", MeCabKoStandardTokenizerFactory.class);
}