diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java index ac23ab35227..9a48592b5b8 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java @@ -44,7 +44,6 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.analysis.CharFilterFactory; import org.elasticsearch.index.analysis.CustomAnalyzer; -import org.elasticsearch.index.analysis.IndexAnalyzers; import org.elasticsearch.index.analysis.NameOrDefinition; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.TokenFilterFactory; @@ -124,11 +123,11 @@ public class TransportAnalyzeAction extends TransportSingleShardAction null); mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY); diff --git a/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java b/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java index f482c6e086e..3693b9eb2ed 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java @@ -560,7 +560,7 @@ public final class AnalysisRegistry implements Closeable { throw new IllegalArgumentException("analyzer name must not start with '_'. got \"" + analyzer.getKey() + "\""); } } - return new IndexAnalyzers(indexSettings, analyzers, normalizers, whitespaceNormalizers); + return new IndexAnalyzers(analyzers, normalizers, whitespaceNormalizers); } private static NamedAnalyzer produceAnalyzer(String name, AnalyzerProvider analyzerFactory, diff --git a/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java b/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java index 4f1cbeb4022..900a6560a66 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/IndexAnalyzers.java @@ -19,8 +19,6 @@ package org.elasticsearch.index.analysis; import org.elasticsearch.core.internal.io.IOUtils; -import org.elasticsearch.index.AbstractIndexComponent; -import org.elasticsearch.index.IndexSettings; import java.io.Closeable; import java.io.IOException; @@ -40,14 +38,13 @@ import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_SEARCH_Q * * @see AnalysisRegistry */ -public final class IndexAnalyzers extends AbstractIndexComponent implements Closeable { +public final class IndexAnalyzers implements Closeable { private final Map analyzers; private final Map normalizers; private final Map whitespaceNormalizers; - public IndexAnalyzers(IndexSettings indexSettings, Map analyzers, Map normalizers, + public IndexAnalyzers(Map analyzers, Map normalizers, Map whitespaceNormalizers) { - super(indexSettings); Objects.requireNonNull(analyzers.get(DEFAULT_ANALYZER_NAME), "the default analyzer must be set"); if (analyzers.get(DEFAULT_ANALYZER_NAME).name().equals(DEFAULT_ANALYZER_NAME) == false) { throw new IllegalStateException( diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java index 3d3dbcf9284..087dfefbbda 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/TransportAnalyzeActionTests.java @@ -59,7 +59,6 @@ import static java.util.Collections.singletonMap; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - /** * Tests for {@link TransportAnalyzeAction}. See the rest tests in the {@code analysis-common} module for places where this code gets a ton * more exercise. @@ -67,6 +66,7 @@ import static org.mockito.Mockito.when; public class TransportAnalyzeActionTests extends ESTestCase { private IndexAnalyzers indexAnalyzers; + private IndexSettings indexSettings; private AnalysisRegistry registry; private int maxTokenCount; private int idxMaxTokenCount; @@ -86,7 +86,7 @@ public class TransportAnalyzeActionTests extends ESTestCase { .put("index.analysis.char_filter.my_append.suffix", "baz") .put("index.analyze.max_token_count", 100) .putList("index.analysis.normalizer.my_normalizer.filter", "lowercase").build(); - IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings); + this.indexSettings = IndexSettingsModule.newIndexSettings("index", indexSettings); Environment environment = TestEnvironment.newEnvironment(settings); AnalysisPlugin plugin = new AnalysisPlugin() { class MockFactory extends AbstractTokenFilterFactory { @@ -146,14 +146,15 @@ public class TransportAnalyzeActionTests extends ESTestCase { } }; registry = new AnalysisModule(environment, singletonList(plugin)).getAnalysisRegistry(); - indexAnalyzers = registry.build(idxSettings); + indexAnalyzers = registry.build(this.indexSettings); maxTokenCount = IndexSettings.MAX_TOKEN_COUNT_SETTING.getDefault(settings); - idxMaxTokenCount = idxSettings.getMaxTokenCount(); + idxMaxTokenCount = this.indexSettings.getMaxTokenCount(); } private IndexService mockIndexService() { IndexService is = mock(IndexService.class); when(is.getIndexAnalyzers()).thenReturn(indexAnalyzers); + when(is.getIndexSettings()).thenReturn(indexSettings); return is; } diff --git a/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java b/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java index f5808c4b0da..4803ee7386b 100644 --- a/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java +++ b/server/src/test/java/org/elasticsearch/index/analysis/IndexAnalyzersTests.java @@ -20,9 +20,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; import java.util.Collections; @@ -38,16 +36,14 @@ public class IndexAnalyzersTests extends ESTestCase { Map analyzers = new HashMap<>(); { NullPointerException ex = expectThrows(NullPointerException.class, - () -> new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers, - Collections.emptyMap(), Collections.emptyMap())); + () -> new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap())); assertEquals("the default analyzer must be set", ex.getMessage()); } { analyzers.put(AnalysisRegistry.DEFAULT_ANALYZER_NAME, new NamedAnalyzer("otherName", AnalyzerScope.INDEX, new StandardAnalyzer())); IllegalStateException ex = expectThrows(IllegalStateException.class, - () -> new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers, - Collections.emptyMap(), Collections.emptyMap())); + () -> new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap())); assertEquals("default analyzer must have the name [default] but was: [otherName]", ex.getMessage()); } } @@ -58,8 +54,7 @@ public class IndexAnalyzersTests extends ESTestCase { analyzers.put(AnalysisRegistry.DEFAULT_ANALYZER_NAME, analyzer); // if only "default" is set in the map, all getters should return the same analyzer - try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers, - Collections.emptyMap(), Collections.emptyMap())) { + try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap())) { assertSame(analyzer, indexAnalyzers.getDefaultIndexAnalyzer()); assertSame(analyzer, indexAnalyzers.getDefaultSearchAnalyzer()); assertSame(analyzer, indexAnalyzers.getDefaultSearchQuoteAnalyzer()); @@ -67,8 +62,7 @@ public class IndexAnalyzersTests extends ESTestCase { analyzers.put(AnalysisRegistry.DEFAULT_SEARCH_ANALYZER_NAME, new NamedAnalyzer("my_search_analyzer", AnalyzerScope.INDEX, new StandardAnalyzer())); - try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers, - Collections.emptyMap(), Collections.emptyMap())) { + try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap())) { assertSame(analyzer, indexAnalyzers.getDefaultIndexAnalyzer()); assertEquals("my_search_analyzer", indexAnalyzers.getDefaultSearchAnalyzer().name()); assertEquals("my_search_analyzer", indexAnalyzers.getDefaultSearchQuoteAnalyzer().name()); @@ -76,8 +70,7 @@ public class IndexAnalyzersTests extends ESTestCase { analyzers.put(AnalysisRegistry.DEFAULT_SEARCH_QUOTED_ANALYZER_NAME, new NamedAnalyzer("my_search_quote_analyzer", AnalyzerScope.INDEX, new StandardAnalyzer())); - try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers, - Collections.emptyMap(), Collections.emptyMap())) { + try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap())) { assertSame(analyzer, indexAnalyzers.getDefaultIndexAnalyzer()); assertEquals("my_search_analyzer", indexAnalyzers.getDefaultSearchAnalyzer().name()); assertEquals("my_search_quote_analyzer", indexAnalyzers.getDefaultSearchQuoteAnalyzer().name()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TypeParsersTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TypeParsersTests.java index 70f469b9637..11e75952bf3 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TypeParsersTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TypeParsersTests.java @@ -69,7 +69,7 @@ public class TypeParsersTests extends ESTestCase { analyzers.put("my_analyzer", new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", AnalysisMode.ALL))); - IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap()); + IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap()); when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers); TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext); @@ -78,7 +78,7 @@ public class TypeParsersTests extends ESTestCase { analyzers = defaultAnalyzers(); analyzers.put("my_analyzer", new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode))); - indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap()); + indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap()); when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers); MapperException ex = expectThrows(MapperException.class, () -> TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext)); @@ -112,7 +112,7 @@ public class TypeParsersTests extends ESTestCase { new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode))); analyzers.put("standard", new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer())); - IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap()); + IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap()); when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers); TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext); @@ -122,7 +122,7 @@ public class TypeParsersTests extends ESTestCase { analyzers.put("my_analyzer", new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode))); analyzers.put("standard", new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer())); - indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap()); + indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap()); when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers); MapperException ex = expectThrows(MapperException.class, () -> TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext)); @@ -142,7 +142,7 @@ public class TypeParsersTests extends ESTestCase { Map analyzers = defaultAnalyzers(); analyzers.put("my_analyzer", new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode))); - IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap()); + IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap()); when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers); MapperException ex = expectThrows(MapperException.class, () -> TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext)); @@ -157,7 +157,7 @@ public class TypeParsersTests extends ESTestCase { new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode))); analyzers.put("standard", new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer())); - indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap()); + indexAnalyzers = new IndexAnalyzers(analyzers, Collections.emptyMap(), Collections.emptyMap()); when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers); TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext); } diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java b/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java index ced2a7bff78..2b597a64c37 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/TranslogHandler.java @@ -63,7 +63,7 @@ public class TranslogHandler implements Engine.TranslogRecoveryRunner { public TranslogHandler(NamedXContentRegistry xContentRegistry, IndexSettings indexSettings) { Map analyzers = new HashMap<>(); analyzers.put(AnalysisRegistry.DEFAULT_ANALYZER_NAME, new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer())); - IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, emptyMap(), emptyMap()); + IndexAnalyzers indexAnalyzers = new IndexAnalyzers(analyzers, emptyMap(), emptyMap()); SimilarityService similarityService = new SimilarityService(indexSettings, null, emptyMap()); MapperRegistry mapperRegistry = new IndicesModule(emptyList()).getMapperRegistry(); mapperService = new MapperService(indexSettings, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry,