From 0f3b72b7bb6ec5eff9a47419828aeeee7af0a7d5 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Wed, 26 Jan 2022 20:46:28 -0600 Subject: [PATCH] [Deprecate] Setting explicit version on analysis component (#1978) Lucene 9 removes the ability to define an explicit version on an analysis component. The version parameter is deprecated at parse time and a warning is issued to the user through the deprecation logger. Signed-off-by: Nicholas Walter Knize --- .../common/ArabicAnalyzerProvider.java | 1 - .../common/ArmenianAnalyzerProvider.java | 1 - .../common/BasqueAnalyzerProvider.java | 1 - .../common/BengaliAnalyzerProvider.java | 1 - .../common/BrazilianAnalyzerProvider.java | 1 - .../common/BulgarianAnalyzerProvider.java | 1 - .../common/CatalanAnalyzerProvider.java | 1 - .../common/ChineseAnalyzerProvider.java | 2 -- .../analysis/common/CjkAnalyzerProvider.java | 1 - .../common/CzechAnalyzerProvider.java | 1 - .../common/DanishAnalyzerProvider.java | 1 - .../common/DutchAnalyzerProvider.java | 1 - .../common/EnglishAnalyzerProvider.java | 1 - .../common/EstonianAnalyzerProvider.java | 1 - .../common/FinnishAnalyzerProvider.java | 1 - .../common/FrenchAnalyzerProvider.java | 1 - .../common/GalicianAnalyzerProvider.java | 1 - .../common/GermanAnalyzerProvider.java | 1 - .../common/GreekAnalyzerProvider.java | 1 - .../common/HindiAnalyzerProvider.java | 1 - .../common/HungarianAnalyzerProvider.java | 1 - .../common/IndonesianAnalyzerProvider.java | 1 - .../common/IrishAnalyzerProvider.java | 1 - .../common/ItalianAnalyzerProvider.java | 1 - .../common/LatvianAnalyzerProvider.java | 1 - .../common/LithuanianAnalyzerProvider.java | 1 - .../common/NorwegianAnalyzerProvider.java | 1 - .../common/PersianAnalyzerProvider.java | 1 - .../common/PortugueseAnalyzerProvider.java | 1 - .../common/RomanianAnalyzerProvider.java | 1 - .../common/RussianAnalyzerProvider.java | 1 - .../common/SnowballAnalyzerProvider.java | 1 - .../common/SoraniAnalyzerProvider.java | 1 - .../common/SpanishAnalyzerProvider.java | 1 - .../common/SwedishAnalyzerProvider.java | 1 - .../analysis/common/ThaiAnalyzerProvider.java | 1 - .../common/TurkishAnalyzerProvider.java | 1 - .../common/CompoundAnalysisTests.java | 1 + .../analysis/pl/PolishAnalyzerProvider.java | 1 - .../analysis/UkrainianAnalyzerProvider.java | 1 - .../AbstractIndexAnalyzerProvider.java | 5 +---- .../analysis/AbstractTokenFilterFactory.java | 9 +------- .../analysis/AbstractTokenizerFactory.java | 8 +------ .../opensearch/index/analysis/Analysis.java | 21 ++++++++----------- .../PreBuiltAnalyzerProviderFactory.java | 9 ++------ .../analysis/SimpleAnalyzerProvider.java | 1 - .../analysis/StandardAnalyzerProvider.java | 1 - .../index/analysis/StopAnalyzerProvider.java | 1 - .../analysis/WhitespaceAnalyzerProvider.java | 1 - .../indices/analysis/AnalysisModuleTests.java | 16 +++----------- .../org/opensearch/index/analysis/test1.json | 4 ++++ 51 files changed, 22 insertions(+), 95 deletions(-) diff --git a/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java b/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java index 397c1b2c922b0..40239cbf38567 100644 --- a/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java +++ b/modules/analysis-common/src/main/java/org/opensearch/analysis/common/ArabicAnalyzerProvider.java @@ -50,7 +50,6 @@ public class ArabicAnalyzerProvider extends AbstractIndexAnalyzerProvider analyze(Settings settings, String analyzerName, String text) throws IOException { diff --git a/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java b/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java index 5a0cf81cc379e..2319b825892ac 100644 --- a/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java +++ b/plugins/analysis-stempel/src/main/java/org/opensearch/index/analysis/pl/PolishAnalyzerProvider.java @@ -46,7 +46,6 @@ public PolishAnalyzerProvider(IndexSettings indexSettings, Environment environme super(indexSettings, name, settings); analyzer = new PolishAnalyzer(PolishAnalyzer.getDefaultStopSet()); - analyzer.setVersion(version); } @Override diff --git a/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java b/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java index b6bb76e0c9893..9beced7d465a6 100644 --- a/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java +++ b/plugins/analysis-ukrainian/src/main/java/org/opensearch/index/analysis/UkrainianAnalyzerProvider.java @@ -48,7 +48,6 @@ public UkrainianAnalyzerProvider(IndexSettings indexSettings, Environment env, S Analysis.parseStopWords(env, settings, UkrainianMorfologikAnalyzer.getDefaultStopSet()), Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) ); - analyzer.setVersion(version); } @Override diff --git a/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java b/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java index fadd6be733637..eb279a9127dc4 100644 --- a/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java +++ b/server/src/main/java/org/opensearch/index/analysis/AbstractIndexAnalyzerProvider.java @@ -33,7 +33,6 @@ package org.opensearch.index.analysis; import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.util.Version; import org.opensearch.common.settings.Settings; import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.IndexSettings; @@ -42,8 +41,6 @@ public abstract class AbstractIndexAnalyzerProvider extends private final String name; - protected final Version version; - /** * Constructs a new analyzer component, with the index name and its settings and the analyzer name. * @@ -53,7 +50,7 @@ public abstract class AbstractIndexAnalyzerProvider extends public AbstractIndexAnalyzerProvider(IndexSettings indexSettings, String name, Settings settings) { super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); + Analysis.parseAndDeprecateAnalysisVersion(name, settings); } /** diff --git a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java index f3222753fabb5..2f91c19c1b78d 100644 --- a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenFilterFactory.java @@ -32,7 +32,6 @@ package org.opensearch.index.analysis; -import org.apache.lucene.util.Version; import org.opensearch.common.settings.Settings; import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.IndexSettings; @@ -41,20 +40,14 @@ public abstract class AbstractTokenFilterFactory extends AbstractIndexComponent private final String name; - protected final Version version; - public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) { super(indexSettings); this.name = name; - this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); + Analysis.parseAndDeprecateAnalysisVersion(name, settings); } @Override public String name() { return this.name; } - - public final Version version() { - return version; - } } diff --git a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java index 49c18d5c1d704..825f8241d3e2e 100644 --- a/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/AbstractTokenizerFactory.java @@ -32,25 +32,19 @@ package org.opensearch.index.analysis; -import org.apache.lucene.util.Version; import org.opensearch.common.settings.Settings; import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.IndexSettings; public abstract class AbstractTokenizerFactory extends AbstractIndexComponent implements TokenizerFactory { - protected final Version version; private final String name; public AbstractTokenizerFactory(IndexSettings indexSettings, Settings settings, String name) { super(indexSettings); - this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); + Analysis.parseAndDeprecateAnalysisVersion(name, settings); this.name = name; } - public final Version version() { - return version; - } - @Override public String name() { return name; diff --git a/server/src/main/java/org/opensearch/index/analysis/Analysis.java b/server/src/main/java/org/opensearch/index/analysis/Analysis.java index 38c5beaf9d80e..8d780bdd4483e 100644 --- a/server/src/main/java/org/opensearch/index/analysis/Analysis.java +++ b/server/src/main/java/org/opensearch/index/analysis/Analysis.java @@ -32,7 +32,6 @@ package org.opensearch.index.analysis; -import org.apache.logging.log4j.Logger; import org.apache.lucene.analysis.CharArraySet; import org.apache.lucene.analysis.ar.ArabicAnalyzer; import org.apache.lucene.analysis.bg.BulgarianAnalyzer; @@ -68,9 +67,8 @@ import org.apache.lucene.analysis.sv.SwedishAnalyzer; import org.apache.lucene.analysis.th.ThaiAnalyzer; import org.apache.lucene.analysis.tr.TurkishAnalyzer; -import org.apache.lucene.util.Version; import org.opensearch.common.Strings; -import org.opensearch.common.lucene.Lucene; +import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; @@ -93,19 +91,18 @@ public class Analysis { - public static Version parseAnalysisVersion(Settings indexSettings, Settings settings, Logger logger) { + private static DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(Analysis.class); + + /** version is deprecated and will be removed; this method parses explicit version and issues a deprecation warning */ + public static void parseAndDeprecateAnalysisVersion(String name, Settings settings) { // check for explicit version on the specific analyzer component String sVersion = settings.get("version"); if (sVersion != null) { - return Lucene.parseVersion(sVersion, Version.LATEST, logger); - } - // check for explicit version on the index itself as default for all analysis components - sVersion = indexSettings.get("index.analysis.version"); - if (sVersion != null) { - return Lucene.parseVersion(sVersion, Version.LATEST, logger); + DEPRECATION_LOGGER.deprecate( + "analyzer.version", + "Setting [version] on analysis [" + name + "] is deprecated, no longer used, and will be removed in a future version." + ); } - // resolve the analysis version based on the version the index was created with - return org.opensearch.Version.indexCreated(indexSettings).luceneVersion; } public static CharArraySet parseStemExclusion(Settings settings, CharArraySet defaultStemExclusion) { diff --git a/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java b/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java index aa3343f69b137..d2c5384153bd2 100644 --- a/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java @@ -60,17 +60,13 @@ public class PreBuiltAnalyzerProviderFactory extends PreConfiguredAnalysisCompon PreBuiltAnalyzerProviderFactory(String name, PreBuiltAnalyzers preBuiltAnalyzer) { super(name, new PreBuiltAnalyzersDelegateCache(name, preBuiltAnalyzer)); this.create = preBuiltAnalyzer::getAnalyzer; - Analyzer analyzer = preBuiltAnalyzer.getAnalyzer(Version.CURRENT); - analyzer.setVersion(Version.CURRENT.luceneVersion); - current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer); + current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, preBuiltAnalyzer.getAnalyzer(Version.CURRENT)); } public PreBuiltAnalyzerProviderFactory(String name, PreBuiltCacheFactory.CachingStrategy cache, Supplier create) { super(name, cache); this.create = version -> create.get(); - Analyzer analyzer = create.get(); - analyzer.setVersion(Version.CURRENT.luceneVersion); - this.current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer); + this.current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, create.get()); } @Override @@ -88,7 +84,6 @@ public AnalyzerProvider get(IndexSettings indexSettings, Environment environm protected AnalyzerProvider create(Version version) { assert Version.CURRENT.equals(version) == false; Analyzer analyzer = create.apply(version); - analyzer.setVersion(version.luceneVersion); return new PreBuiltAnalyzerProvider(getName(), AnalyzerScope.INDICES, analyzer); } diff --git a/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java b/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java index 6fff247df63d7..85d25aaa753e6 100644 --- a/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java +++ b/server/src/main/java/org/opensearch/index/analysis/SimpleAnalyzerProvider.java @@ -44,7 +44,6 @@ public class SimpleAnalyzerProvider extends AbstractIndexAnalyzerProvider