Skip to content

Commit

Permalink
[Remove] Setting explicit version on analysis component (#1986)
Browse files Browse the repository at this point in the history
Lucene 9 removes the ability to define an explicit version on an analysis
component so remove the the version parameter and deprecation warning
prohibiting users from explicitly setting versioned analyzers.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize authored Jan 27, 2022
1 parent 054595b commit 334f0d9
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public void testDictionaryDecompounder() throws Exception {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
public AbstractIndexAnalyzerProvider(IndexSettings indexSettings, String name, Settings settings) {
super(indexSettings);
this.name = name;
Analysis.parseAndDeprecateAnalysisVersion(name, settings);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public abstract class AbstractTokenFilterFactory extends AbstractIndexComponent
public AbstractTokenFilterFactory(IndexSettings indexSettings, String name, Settings settings) {
super(indexSettings);
this.name = name;
Analysis.parseAndDeprecateAnalysisVersion(name, settings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public abstract class AbstractTokenizerFactory extends AbstractIndexComponent im

public AbstractTokenizerFactory(IndexSettings indexSettings, Settings settings, String name) {
super(indexSettings);
Analysis.parseAndDeprecateAnalysisVersion(name, settings);
this.name = name;
}

Expand Down
15 changes: 0 additions & 15 deletions server/src/main/java/org/opensearch/index/analysis/Analysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.apache.lucene.analysis.th.ThaiAnalyzer;
import org.apache.lucene.analysis.tr.TurkishAnalyzer;
import org.opensearch.common.Strings;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.Environment;

Expand All @@ -91,20 +90,6 @@

public class Analysis {

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) {
DEPRECATION_LOGGER.deprecate(
"analyzer.version",
"Setting [version] on analysis [" + name + "] is deprecated, no longer used, and will be removed in a future version."
);
}
}

public static CharArraySet parseStemExclusion(Settings settings, CharArraySet defaultStemExclusion) {
String value = settings.get("stem_exclusion");
if ("_none_".equals(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.hunspell.Dictionary;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NIOFSDirectory;
Expand Down Expand Up @@ -92,7 +91,6 @@
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

public class AnalysisModuleTests extends OpenSearchTestCase {
private final Settings emptyNodeSettings = Settings.builder()
Expand Down Expand Up @@ -138,28 +136,11 @@ private Settings loadFromClasspath(String path) throws IOException {
public void testSimpleConfigurationJson() throws IOException {
Settings settings = loadFromClasspath("/org/opensearch/index/analysis/test1.json");
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 {
Settings settings = loadFromClasspath("/org/opensearch/index/analysis/test1.yml");
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 {
String yaml = "/org/opensearch/index/analysis/test1.yml";
Version version = VersionUtils.randomVersion(random());
Settings settings2 = Settings.builder()
.loadFromStream(yaml, getClass().getResourceAsStream(yaml), false)
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
.put(IndexMetadata.SETTING_VERSION_CREATED, version)
.build();
AnalysisRegistry newRegistry = getNewRegistry(settings2);
IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings2);

assertThat(indexAnalyzers.get("custom7").analyzer(), is(instanceOf(StandardAnalyzer.class)));
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
"custom6":{
"tokenizer":"standard",
"position_increment_gap": 256
},
"custom7":{
"type":"standard",
"version": 3.6
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ index :
custom6 :
tokenizer : standard
position_increment_gap: 256
custom7 :
type : standard
version: 3.6

0 comments on commit 334f0d9

Please sign in to comment.