summaryrefslogtreecommitdiff
path: root/plugins/analysis-stempel
diff options
context:
space:
mode:
authorSimon Willnauer <simonw@apache.org>2015-10-28 22:19:44 +0100
committerSimon Willnauer <simonw@apache.org>2015-10-30 11:40:18 +0100
commitaa38d053d75c4cc8134ecff0c23d8c4c9640c704 (patch)
tree3846250c72c707fdee2130f25d4864afd8709a13 /plugins/analysis-stempel
parent7f179cdab00cdffd1e50cb7bcbfd1ba2b78724e7 (diff)
Simplify Analysis registration and configuration
This change moves all the analysis component registration to the node level and removes the significant API overhead to register tokenfilter, tokenizer, charfilter and analyzer. All registration is done without guice interaction such that real factories via functional interfaces are passed instead of class objects that are instantiated at runtime. This change also hides the internal analyzer caching that was done previously in the IndicesAnalysisService entirely and decouples all analysis registration and creation from dependency injection.
Diffstat (limited to 'plugins/analysis-stempel')
-rw-r--r--plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalysisBinderProcessor.java36
-rw-r--r--plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java6
-rw-r--r--plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishStemTokenFilterFactory.java5
-rw-r--r--plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysis.java65
-rw-r--r--plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysisModule.java32
-rw-r--r--plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java18
-rw-r--r--plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java21
-rw-r--r--plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java20
8 files changed, 31 insertions, 172 deletions
diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalysisBinderProcessor.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalysisBinderProcessor.java
deleted file mode 100644
index 408d80cd98..0000000000
--- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalysisBinderProcessor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.index.analysis.pl;
-
-import org.elasticsearch.index.analysis.AnalysisModule;
-
-/**
- */
-public class PolishAnalysisBinderProcessor extends AnalysisModule.AnalysisBinderProcessor {
-
- @Override
- public void processAnalyzers(AnalyzersBindings analyzersBindings) {
- analyzersBindings.processAnalyzer("polish", PolishAnalyzerProvider.class);
- }
- @Override
- public void processTokenFilters(TokenFiltersBindings tokenFiltersBindings) {
- tokenFiltersBindings.processTokenFilter("polish_stem", PolishStemTokenFilterFactory.class);
- }
-}
diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java
index 4c6ea0188a..d80939cea0 100644
--- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java
+++ b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishAnalyzerProvider.java
@@ -20,9 +20,8 @@
package org.elasticsearch.index.analysis.pl;
import org.apache.lucene.analysis.pl.PolishAnalyzer;
-import org.elasticsearch.common.inject.Inject;
-import org.elasticsearch.common.inject.assistedinject.Assisted;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;
@@ -32,8 +31,7 @@ public class PolishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Polish
private final PolishAnalyzer analyzer;
- @Inject
- public PolishAnalyzerProvider(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) {
+ public PolishAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings);
analyzer = new PolishAnalyzer(PolishAnalyzer.getDefaultStopSet());
diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishStemTokenFilterFactory.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishStemTokenFilterFactory.java
index 15eda54751..0ee789f66e 100644
--- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishStemTokenFilterFactory.java
+++ b/plugins/analysis-stempel/src/main/java/org/elasticsearch/index/analysis/pl/PolishStemTokenFilterFactory.java
@@ -24,9 +24,8 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.stempel.StempelFilter;
import org.apache.lucene.analysis.stempel.StempelStemmer;
import org.egothor.stemmer.Trie;
-import org.elasticsearch.common.inject.Inject;
-import org.elasticsearch.common.inject.assistedinject.Assisted;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
@@ -38,7 +37,7 @@ public class PolishStemTokenFilterFactory extends AbstractTokenFilterFactory {
private final StempelStemmer stemmer;
- @Inject public PolishStemTokenFilterFactory(IndexSettings indexSettings, @Assisted String name, @Assisted Settings settings) {
+ public PolishStemTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings);
Trie tire;
try {
diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysis.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysis.java
deleted file mode 100644
index ae7aa3b747..0000000000
--- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysis.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.indices.analysis.pl;
-
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.analysis.pl.PolishAnalyzer;
-import org.apache.lucene.analysis.stempel.StempelFilter;
-import org.apache.lucene.analysis.stempel.StempelStemmer;
-import org.egothor.stemmer.Trie;
-import org.elasticsearch.common.component.AbstractComponent;
-import org.elasticsearch.common.inject.Inject;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.analysis.AnalyzerScope;
-import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory;
-import org.elasticsearch.index.analysis.PreBuiltTokenFilterFactoryFactory;
-import org.elasticsearch.index.analysis.TokenFilterFactory;
-import org.elasticsearch.indices.analysis.IndicesAnalysisService;
-
-import java.io.IOException;
-
-/**
- * Registers indices level analysis components so, if not explicitly configured, will be shared
- * among all indices.
- */
-public class PolishIndicesAnalysis extends AbstractComponent {
-
- @Inject
- public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
- super(settings);
- indicesAnalysisService.analyzerProviderFactories().put("polish", new PreBuiltAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer()));
-
- indicesAnalysisService.tokenFilterFactories().put("polish_stem", new PreBuiltTokenFilterFactoryFactory(new TokenFilterFactory() {
- @Override public String name() {
- return "polish_stem";
- }
-
- @Override public TokenStream create(TokenStream tokenStream) {
- Trie tire;
- try {
- tire = StempelStemmer.load(PolishAnalyzer.class.getResourceAsStream(PolishAnalyzer.DEFAULT_STEMMER_FILE));
- } catch (IOException ex) {
- throw new RuntimeException("Unable to load default stemming tables", ex);
- }
- return new StempelFilter(tokenStream, new StempelStemmer(tire));
- }
- }));
- }
-}
diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysisModule.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysisModule.java
deleted file mode 100644
index e25bec3cf4..0000000000
--- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysisModule.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.indices.analysis.pl;
-
-import org.elasticsearch.common.inject.AbstractModule;
-
-/**
- */
-public class PolishIndicesAnalysisModule extends AbstractModule {
-
- @Override
- protected void configure() {
- bind(PolishIndicesAnalysis.class).asEagerSingleton();
- }
-}
diff --git a/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java b/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java
index b22cda173a..07f50ed773 100644
--- a/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java
+++ b/plugins/analysis-stempel/src/main/java/org/elasticsearch/plugin/analysis/stempel/AnalysisStempelPlugin.java
@@ -19,15 +19,11 @@
package org.elasticsearch.plugin.analysis.stempel;
-import org.elasticsearch.common.inject.Module;
-import org.elasticsearch.index.analysis.AnalysisModule;
-import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor;
-import org.elasticsearch.indices.analysis.pl.PolishIndicesAnalysisModule;
+import org.elasticsearch.index.analysis.pl.PolishAnalyzerProvider;
+import org.elasticsearch.index.analysis.pl.PolishStemTokenFilterFactory;
+import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.plugins.Plugin;
-import java.util.Collection;
-import java.util.Collections;
-
/**
*
*/
@@ -43,12 +39,8 @@ public class AnalysisStempelPlugin extends Plugin {
return "Stempel (Polish) analysis support";
}
- @Override
- public Collection<Module> nodeModules() {
- return Collections.<Module>singletonList(new PolishIndicesAnalysisModule());
- }
-
public void onModule(AnalysisModule module) {
- module.addProcessor(new PolishAnalysisBinderProcessor());
+ module.registerAnalyzer("polish", PolishAnalyzerProvider::new);
+ module.registerTokenFilter("polish_stem", PolishStemTokenFilterFactory::new);
}
}
diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java
index 1a0376b721..91990ef4a5 100644
--- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java
+++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/PolishAnalysisTests.java
@@ -30,13 +30,16 @@ import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor;
import org.elasticsearch.index.analysis.pl.PolishStemTokenFilterFactory;
-import org.elasticsearch.indices.analysis.IndicesAnalysisService;
+import org.elasticsearch.indices.analysis.AnalysisModule;
+import org.elasticsearch.plugin.analysis.stempel.AnalysisStempelPlugin;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import org.hamcrest.MatcherAssert;
+import java.io.IOException;
+import java.util.Collections;
+
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
import static org.hamcrest.Matchers.instanceOf;
@@ -44,21 +47,21 @@ import static org.hamcrest.Matchers.instanceOf;
/**
*/
public class PolishAnalysisTests extends ESTestCase {
- public void testDefaultsPolishAnalysis() {
+ public void testDefaultsPolishAnalysis() throws IOException {
Index index = new Index("test");
Settings settings = settingsBuilder()
.put("path.home", createTempDir())
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build();
- Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector();
- Injector injector = new ModulesBuilder().add(
- new IndexSettingsModule(index, settings),
- new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new PolishAnalysisBinderProcessor()))
- .createChildInjector(parentInjector);
- AnalysisService analysisService = injector.getInstance(AnalysisService.class);
+ AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
+ new AnalysisStempelPlugin().onModule(analysisModule);
+ Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings),
+ new EnvironmentModule(new Environment(settings)), analysisModule)
+ .createInjector();
+ final AnalysisService analysisService = parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings, Collections.emptyList()));
TokenFilterFactory tokenizerFactory = analysisService.tokenFilter("polish_stem");
MatcherAssert.assertThat(tokenizerFactory, instanceOf(PolishStemTokenFilterFactory.class));
diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java
index 06be6f6792..a1f178166f 100644
--- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java
+++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/SimplePolishTokenFilterTests.java
@@ -33,13 +33,14 @@ import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule;
import org.elasticsearch.index.Index;
-import org.elasticsearch.index.analysis.pl.PolishAnalysisBinderProcessor;
-import org.elasticsearch.indices.analysis.IndicesAnalysisService;
+import org.elasticsearch.indices.analysis.AnalysisModule;
+import org.elasticsearch.plugin.analysis.stempel.AnalysisStempelPlugin;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import java.io.IOException;
import java.io.StringReader;
+import java.util.Collections;
import static org.hamcrest.Matchers.equalTo;
@@ -96,13 +97,12 @@ public class SimplePolishTokenFilterTests extends ESTestCase {
}
}
- private AnalysisService createAnalysisService(Index index, Settings settings) {
- Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings))).createInjector();
- Injector injector = new ModulesBuilder().add(
- new IndexSettingsModule(index, settings),
- new AnalysisModule(settings, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new PolishAnalysisBinderProcessor()))
- .createChildInjector(parentInjector);
-
- return injector.getInstance(AnalysisService.class);
+ private AnalysisService createAnalysisService(Index index, Settings settings) throws IOException {
+ AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
+ new AnalysisStempelPlugin().onModule(analysisModule);
+ Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings),
+ new EnvironmentModule(new Environment(settings)), analysisModule)
+ .createInjector();
+ return parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings, Collections.emptyList()));
}
}