[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 <nknize@apache.org>
This commit is contained in:
Nick Knize 2022-01-26 20:46:28 -06:00 committed by GitHub
parent a18b4e35b8
commit 0f3b72b7bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 22 additions and 95 deletions

View File

@ -50,7 +50,6 @@ public class ArabicAnalyzerProvider extends AbstractIndexAnalyzerProvider<Arabic
Analysis.parseStopWords(env, settings, ArabicAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, ArabicAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
arabicAnalyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class ArmenianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Arme
Analysis.parseStopWords(env, settings, ArmenianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, ArmenianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class BasqueAnalyzerProvider extends AbstractIndexAnalyzerProvider<Basque
Analysis.parseStopWords(env, settings, BasqueAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, BasqueAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class BengaliAnalyzerProvider extends AbstractIndexAnalyzerProvider<Benga
Analysis.parseStopWords(env, settings, BengaliAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, BengaliAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class BrazilianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Bra
Analysis.parseStopWords(env, settings, BrazilianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, BrazilianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class BulgarianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Bul
Analysis.parseStopWords(env, settings, BulgarianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, BulgarianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class CatalanAnalyzerProvider extends AbstractIndexAnalyzerProvider<Catal
Analysis.parseStopWords(env, settings, CatalanAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, CatalanAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,8 +50,6 @@ public class ChineseAnalyzerProvider extends AbstractIndexAnalyzerProvider<Stand
super(indexSettings, name, settings); super(indexSettings, name, settings);
// old index: best effort // old index: best effort
analyzer = new StandardAnalyzer(EnglishAnalyzer.ENGLISH_STOP_WORDS_SET); analyzer = new StandardAnalyzer(EnglishAnalyzer.ENGLISH_STOP_WORDS_SET);
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -49,7 +49,6 @@ public class CjkAnalyzerProvider extends AbstractIndexAnalyzerProvider<CJKAnalyz
CharArraySet stopWords = Analysis.parseStopWords(env, settings, CJKAnalyzer.getDefaultStopSet()); CharArraySet stopWords = Analysis.parseStopWords(env, settings, CJKAnalyzer.getDefaultStopSet());
analyzer = new CJKAnalyzer(stopWords); analyzer = new CJKAnalyzer(stopWords);
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class CzechAnalyzerProvider extends AbstractIndexAnalyzerProvider<CzechAn
Analysis.parseStopWords(env, settings, CzechAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, CzechAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class DanishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Danish
Analysis.parseStopWords(env, settings, DanishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, DanishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class DutchAnalyzerProvider extends AbstractIndexAnalyzerProvider<DutchAn
Analysis.parseStopWords(env, settings, DutchAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, DutchAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class EnglishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Engli
Analysis.parseStopWords(env, settings, EnglishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, EnglishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class EstonianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Esto
Analysis.parseStopWords(env, settings, EstonianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, EstonianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class FinnishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Finni
Analysis.parseStopWords(env, settings, FinnishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, FinnishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class FrenchAnalyzerProvider extends AbstractIndexAnalyzerProvider<French
Analysis.parseStopWords(env, settings, FrenchAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, FrenchAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class GalicianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Gali
Analysis.parseStopWords(env, settings, GalicianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, GalicianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class GermanAnalyzerProvider extends AbstractIndexAnalyzerProvider<German
Analysis.parseStopWords(env, settings, GermanAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, GermanAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -46,7 +46,6 @@ public class GreekAnalyzerProvider extends AbstractIndexAnalyzerProvider<GreekAn
GreekAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) { GreekAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
super(indexSettings, name, settings); super(indexSettings, name, settings);
analyzer = new GreekAnalyzer(Analysis.parseStopWords(env, settings, GreekAnalyzer.getDefaultStopSet())); analyzer = new GreekAnalyzer(Analysis.parseStopWords(env, settings, GreekAnalyzer.getDefaultStopSet()));
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class HindiAnalyzerProvider extends AbstractIndexAnalyzerProvider<HindiAn
Analysis.parseStopWords(env, settings, HindiAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, HindiAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class HungarianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Hun
Analysis.parseStopWords(env, settings, HungarianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, HungarianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class IndonesianAnalyzerProvider extends AbstractIndexAnalyzerProvider<In
Analysis.parseStopWords(env, settings, IndonesianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, IndonesianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -53,7 +53,6 @@ public class IrishAnalyzerProvider extends AbstractIndexAnalyzerProvider<IrishAn
Analysis.parseStopWords(env, settings, IrishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, IrishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class ItalianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Itali
Analysis.parseStopWords(env, settings, ItalianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, ItalianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class LatvianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Latvi
Analysis.parseStopWords(env, settings, LatvianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, LatvianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -53,7 +53,6 @@ public class LithuanianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Li
Analysis.parseStopWords(env, settings, LithuanianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, LithuanianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class NorwegianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Nor
Analysis.parseStopWords(env, settings, NorwegianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, NorwegianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -46,7 +46,6 @@ public class PersianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Persi
PersianAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) { PersianAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
super(indexSettings, name, settings); super(indexSettings, name, settings);
analyzer = new PersianAnalyzer(Analysis.parseStopWords(env, settings, PersianAnalyzer.getDefaultStopSet())); analyzer = new PersianAnalyzer(Analysis.parseStopWords(env, settings, PersianAnalyzer.getDefaultStopSet()));
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class PortugueseAnalyzerProvider extends AbstractIndexAnalyzerProvider<Po
Analysis.parseStopWords(env, settings, PortugueseAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, PortugueseAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class RomanianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Roma
Analysis.parseStopWords(env, settings, RomanianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, RomanianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class RussianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Russi
Analysis.parseStopWords(env, settings, RussianAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, RussianAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -83,7 +83,6 @@ public class SnowballAnalyzerProvider extends AbstractIndexAnalyzerProvider<Snow
CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords); CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);
analyzer = new SnowballAnalyzer(language, stopWords); analyzer = new SnowballAnalyzer(language, stopWords);
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -53,7 +53,6 @@ public class SoraniAnalyzerProvider extends AbstractIndexAnalyzerProvider<Sorani
Analysis.parseStopWords(env, settings, SoraniAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, SoraniAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class SpanishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Spani
Analysis.parseStopWords(env, settings, SpanishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, SpanishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class SwedishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Swedi
Analysis.parseStopWords(env, settings, SwedishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, SwedishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -46,7 +46,6 @@ public class ThaiAnalyzerProvider extends AbstractIndexAnalyzerProvider<ThaiAnal
ThaiAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) { ThaiAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
super(indexSettings, name, settings); super(indexSettings, name, settings);
analyzer = new ThaiAnalyzer(Analysis.parseStopWords(env, settings, ThaiAnalyzer.getDefaultStopSet())); analyzer = new ThaiAnalyzer(Analysis.parseStopWords(env, settings, ThaiAnalyzer.getDefaultStopSet()));
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -50,7 +50,6 @@ public class TurkishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Turki
Analysis.parseStopWords(env, settings, TurkishAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, TurkishAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -81,6 +81,7 @@ public class CompoundAnalysisTests extends OpenSearchTestCase {
hasItems("donau", "dampf", "schiff", "donaudampfschiff", "spargel", "creme", "suppe", "spargelcremesuppe") hasItems("donau", "dampf", "schiff", "donaudampfschiff", "spargel", "creme", "suppe", "spargelcremesuppe")
); );
} }
assertWarnings("Setting [version] on analysis [custom7] is deprecated, no longer used, and will be removed in a future version.");
} }
private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException { private List<String> analyze(Settings settings, String analyzerName, String text) throws IOException {

View File

@ -46,7 +46,6 @@ public class PolishAnalyzerProvider extends AbstractIndexAnalyzerProvider<Polish
super(indexSettings, name, settings); super(indexSettings, name, settings);
analyzer = new PolishAnalyzer(PolishAnalyzer.getDefaultStopSet()); analyzer = new PolishAnalyzer(PolishAnalyzer.getDefaultStopSet());
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -48,7 +48,6 @@ public class UkrainianAnalyzerProvider extends AbstractIndexAnalyzerProvider<Ukr
Analysis.parseStopWords(env, settings, UkrainianMorfologikAnalyzer.getDefaultStopSet()), Analysis.parseStopWords(env, settings, UkrainianMorfologikAnalyzer.getDefaultStopSet()),
Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET) Analysis.parseStemExclusion(settings, CharArraySet.EMPTY_SET)
); );
analyzer.setVersion(version);
} }
@Override @Override

View File

@ -33,7 +33,6 @@
package org.opensearch.index.analysis; package org.opensearch.index.analysis;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.util.Version;
import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.Settings;
import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.AbstractIndexComponent;
import org.opensearch.index.IndexSettings; import org.opensearch.index.IndexSettings;
@ -42,8 +41,6 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
private final String name; private final String name;
protected final Version version;
/** /**
* Constructs a new analyzer component, with the index name and its settings and the analyzer name. * Constructs a new analyzer component, with the index name and its settings and the analyzer name.
* *
@ -53,7 +50,7 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
public AbstractIndexAnalyzerProvider(IndexSettings indexSettings, String name, Settings settings) { public AbstractIndexAnalyzerProvider(IndexSettings indexSettings, String name, Settings settings) {
super(indexSettings); super(indexSettings);
this.name = name; this.name = name;
this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); Analysis.parseAndDeprecateAnalysisVersion(name, settings);
} }
/** /**

View File

@ -32,7 +32,6 @@
package org.opensearch.index.analysis; package org.opensearch.index.analysis;
import org.apache.lucene.util.Version;
import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.Settings;
import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.AbstractIndexComponent;
import org.opensearch.index.IndexSettings; import org.opensearch.index.IndexSettings;
@ -41,20 +40,14 @@ public abstract class AbstractTokenFilterFactory extends AbstractIndexComponent
private final String name; private final String name;
protected final Version version;
public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) { public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) {
super(indexSettings); super(indexSettings);
this.name = name; this.name = name;
this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); Analysis.parseAndDeprecateAnalysisVersion(name, settings);
} }
@Override @Override
public String name() { public String name() {
return this.name; return this.name;
} }
public final Version version() {
return version;
}
} }

View File

@ -32,25 +32,19 @@
package org.opensearch.index.analysis; package org.opensearch.index.analysis;
import org.apache.lucene.util.Version;
import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.Settings;
import org.opensearch.index.AbstractIndexComponent; import org.opensearch.index.AbstractIndexComponent;
import org.opensearch.index.IndexSettings; import org.opensearch.index.IndexSettings;
public abstract class AbstractTokenizerFactory extends AbstractIndexComponent implements TokenizerFactory { public abstract class AbstractTokenizerFactory extends AbstractIndexComponent implements TokenizerFactory {
protected final Version version;
private final String name; private final String name;
public AbstractTokenizerFactory(IndexSettings indexSettings, Settings settings, String name) { public AbstractTokenizerFactory(IndexSettings indexSettings, Settings settings, String name) {
super(indexSettings); super(indexSettings);
this.version = Analysis.parseAnalysisVersion(this.indexSettings.getSettings(), settings, logger); Analysis.parseAndDeprecateAnalysisVersion(name, settings);
this.name = name; this.name = name;
} }
public final Version version() {
return version;
}
@Override @Override
public String name() { public String name() {
return name; return name;

View File

@ -32,7 +32,6 @@
package org.opensearch.index.analysis; package org.opensearch.index.analysis;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.analysis.CharArraySet; import org.apache.lucene.analysis.CharArraySet;
import org.apache.lucene.analysis.ar.ArabicAnalyzer; import org.apache.lucene.analysis.ar.ArabicAnalyzer;
import org.apache.lucene.analysis.bg.BulgarianAnalyzer; import org.apache.lucene.analysis.bg.BulgarianAnalyzer;
@ -68,9 +67,8 @@ import org.apache.lucene.analysis.ru.RussianAnalyzer;
import org.apache.lucene.analysis.sv.SwedishAnalyzer; import org.apache.lucene.analysis.sv.SwedishAnalyzer;
import org.apache.lucene.analysis.th.ThaiAnalyzer; import org.apache.lucene.analysis.th.ThaiAnalyzer;
import org.apache.lucene.analysis.tr.TurkishAnalyzer; import org.apache.lucene.analysis.tr.TurkishAnalyzer;
import org.apache.lucene.util.Version;
import org.opensearch.common.Strings; 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.common.settings.Settings;
import org.opensearch.env.Environment; import org.opensearch.env.Environment;
@ -93,19 +91,18 @@ import static java.util.Collections.unmodifiableMap;
public class Analysis { 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 // check for explicit version on the specific analyzer component
String sVersion = settings.get("version"); String sVersion = settings.get("version");
if (sVersion != null) { 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."
);
} }
// 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);
}
// 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) { public static CharArraySet parseStemExclusion(Settings settings, CharArraySet defaultStemExclusion) {

View File

@ -60,17 +60,13 @@ public class PreBuiltAnalyzerProviderFactory extends PreConfiguredAnalysisCompon
PreBuiltAnalyzerProviderFactory(String name, PreBuiltAnalyzers preBuiltAnalyzer) { PreBuiltAnalyzerProviderFactory(String name, PreBuiltAnalyzers preBuiltAnalyzer) {
super(name, new PreBuiltAnalyzersDelegateCache(name, preBuiltAnalyzer)); super(name, new PreBuiltAnalyzersDelegateCache(name, preBuiltAnalyzer));
this.create = preBuiltAnalyzer::getAnalyzer; this.create = preBuiltAnalyzer::getAnalyzer;
Analyzer analyzer = preBuiltAnalyzer.getAnalyzer(Version.CURRENT); current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, preBuiltAnalyzer.getAnalyzer(Version.CURRENT));
analyzer.setVersion(Version.CURRENT.luceneVersion);
current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer);
} }
public PreBuiltAnalyzerProviderFactory(String name, PreBuiltCacheFactory.CachingStrategy cache, Supplier<Analyzer> create) { public PreBuiltAnalyzerProviderFactory(String name, PreBuiltCacheFactory.CachingStrategy cache, Supplier<Analyzer> create) {
super(name, cache); super(name, cache);
this.create = version -> create.get(); this.create = version -> create.get();
Analyzer analyzer = create.get(); this.current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, create.get());
analyzer.setVersion(Version.CURRENT.luceneVersion);
this.current = new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer);
} }
@Override @Override
@ -88,7 +84,6 @@ public class PreBuiltAnalyzerProviderFactory extends PreConfiguredAnalysisCompon
protected AnalyzerProvider<?> create(Version version) { protected AnalyzerProvider<?> create(Version version) {
assert Version.CURRENT.equals(version) == false; assert Version.CURRENT.equals(version) == false;
Analyzer analyzer = create.apply(version); Analyzer analyzer = create.apply(version);
analyzer.setVersion(version.luceneVersion);
return new PreBuiltAnalyzerProvider(getName(), AnalyzerScope.INDICES, analyzer); return new PreBuiltAnalyzerProvider(getName(), AnalyzerScope.INDICES, analyzer);
} }

View File

@ -44,7 +44,6 @@ public class SimpleAnalyzerProvider extends AbstractIndexAnalyzerProvider<Simple
public SimpleAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) { public SimpleAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings); super(indexSettings, name, settings);
this.simpleAnalyzer = new SimpleAnalyzer(); this.simpleAnalyzer = new SimpleAnalyzer();
this.simpleAnalyzer.setVersion(version);
} }
@Override @Override

View File

@ -48,7 +48,6 @@ public class StandardAnalyzerProvider extends AbstractIndexAnalyzerProvider<Stan
CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords); CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);
int maxTokenLength = settings.getAsInt("max_token_length", StandardAnalyzer.DEFAULT_MAX_TOKEN_LENGTH); int maxTokenLength = settings.getAsInt("max_token_length", StandardAnalyzer.DEFAULT_MAX_TOKEN_LENGTH);
standardAnalyzer = new StandardAnalyzer(stopWords); standardAnalyzer = new StandardAnalyzer(stopWords);
standardAnalyzer.setVersion(version);
standardAnalyzer.setMaxTokenLength(maxTokenLength); standardAnalyzer.setMaxTokenLength(maxTokenLength);
} }

View File

@ -47,7 +47,6 @@ public class StopAnalyzerProvider extends AbstractIndexAnalyzerProvider<StopAnal
super(indexSettings, name, settings); super(indexSettings, name, settings);
CharArraySet stopWords = Analysis.parseStopWords(env, settings, EnglishAnalyzer.ENGLISH_STOP_WORDS_SET); CharArraySet stopWords = Analysis.parseStopWords(env, settings, EnglishAnalyzer.ENGLISH_STOP_WORDS_SET);
this.stopAnalyzer = new StopAnalyzer(stopWords); this.stopAnalyzer = new StopAnalyzer(stopWords);
this.stopAnalyzer.setVersion(version);
} }
@Override @Override

View File

@ -44,7 +44,6 @@ public class WhitespaceAnalyzerProvider extends AbstractIndexAnalyzerProvider<Wh
public WhitespaceAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) { public WhitespaceAnalyzerProvider(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings); super(indexSettings, name, settings);
this.analyzer = new WhitespaceAnalyzer(); this.analyzer = new WhitespaceAnalyzer();
this.analyzer.setVersion(version);
} }
@Override @Override

View File

@ -57,7 +57,6 @@ import org.opensearch.index.analysis.AnalysisRegistry;
import org.opensearch.index.analysis.CharFilterFactory; import org.opensearch.index.analysis.CharFilterFactory;
import org.opensearch.index.analysis.CustomAnalyzer; import org.opensearch.index.analysis.CustomAnalyzer;
import org.opensearch.index.analysis.IndexAnalyzers; import org.opensearch.index.analysis.IndexAnalyzers;
import org.opensearch.index.analysis.NamedAnalyzer;
import org.opensearch.index.analysis.PreConfiguredCharFilter; import org.opensearch.index.analysis.PreConfiguredCharFilter;
import org.opensearch.index.analysis.PreConfiguredTokenFilter; import org.opensearch.index.analysis.PreConfiguredTokenFilter;
import org.opensearch.index.analysis.PreConfiguredTokenizer; import org.opensearch.index.analysis.PreConfiguredTokenizer;
@ -139,11 +138,13 @@ public class AnalysisModuleTests extends OpenSearchTestCase {
public void testSimpleConfigurationJson() throws IOException { public void testSimpleConfigurationJson() throws IOException {
Settings settings = loadFromClasspath("/org/opensearch/index/analysis/test1.json"); Settings settings = loadFromClasspath("/org/opensearch/index/analysis/test1.json");
testSimpleConfiguration(settings); testSimpleConfiguration(settings);
assertWarnings("Setting [version] on analysis [custom7] is deprecated, no longer used, and will be removed in a future version.");
} }
public void testSimpleConfigurationYaml() throws IOException { public void testSimpleConfigurationYaml() throws IOException {
Settings settings = loadFromClasspath("/org/opensearch/index/analysis/test1.yml"); Settings settings = loadFromClasspath("/org/opensearch/index/analysis/test1.yml");
testSimpleConfiguration(settings); testSimpleConfiguration(settings);
assertWarnings("Setting [version] on analysis [custom7] is deprecated, no longer used, and will be removed in a future version.");
} }
public void testVersionedAnalyzers() throws Exception { public void testVersionedAnalyzers() throws Exception {
@ -157,19 +158,8 @@ public class AnalysisModuleTests extends OpenSearchTestCase {
AnalysisRegistry newRegistry = getNewRegistry(settings2); AnalysisRegistry newRegistry = getNewRegistry(settings2);
IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings2); IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings2);
// registry always has the current version
assertThat(newRegistry.getAnalyzer("default"), is(instanceOf(NamedAnalyzer.class)));
NamedAnalyzer defaultNamedAnalyzer = (NamedAnalyzer) newRegistry.getAnalyzer("default");
assertThat(defaultNamedAnalyzer.analyzer(), is(instanceOf(StandardAnalyzer.class)));
assertEquals(Version.CURRENT.luceneVersion, defaultNamedAnalyzer.analyzer().getVersion());
// analysis service has the expected version
assertThat(indexAnalyzers.get("standard").analyzer(), is(instanceOf(StandardAnalyzer.class)));
assertEquals(version.luceneVersion, indexAnalyzers.get("standard").analyzer().getVersion());
assertEquals(version.luceneVersion, indexAnalyzers.get("stop").analyzer().getVersion());
assertThat(indexAnalyzers.get("custom7").analyzer(), is(instanceOf(StandardAnalyzer.class))); assertThat(indexAnalyzers.get("custom7").analyzer(), is(instanceOf(StandardAnalyzer.class)));
assertEquals(org.apache.lucene.util.Version.fromBits(3, 6, 0), indexAnalyzers.get("custom7").analyzer().getVersion()); assertWarnings("Setting [version] on analysis [custom7] is deprecated, no longer used, and will be removed in a future version.");
} }
private void testSimpleConfiguration(Settings settings) throws IOException { private void testSimpleConfiguration(Settings settings) throws IOException {

View File

@ -35,6 +35,10 @@
"custom6":{ "custom6":{
"tokenizer":"standard", "tokenizer":"standard",
"position_increment_gap": 256 "position_increment_gap": 256
},
"custom7":{
"type":"standard",
"version": 3.6
} }
} }
} }