Skip to content

Commit

Permalink
[Analysis] Deprecate Standard Html Strip Analyzer
Browse files Browse the repository at this point in the history
Use expectThrows
Change versions for deprecation log

Related elastic#4704
  • Loading branch information
johtani committed Nov 5, 2018
1 parent 76a42c5 commit d57aff6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public class StandardHtmlStripAnalyzerProvider extends AbstractIndexAnalyzerProv
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0_alpha1)) {
throw new IllegalArgumentException("[standard_html_strip] analyzer is not supported for new indices, " +
"use a custom analyzer using [standard] tokenizer and [html_strip] char_filter, plus [lowercase] filter");
}
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_5_0)) {
} else {
DEPRECATION_LOGGER.deprecatedAndMaybeLog("standard_html_strip_deprecation",
"Deprecated analyzer [standard_html_strip] used, " +
"replace it with a custom analyzer using [standard] tokenizer and [html_strip] char_filter, plus [lowercase] filter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.test.VersionUtils;
import org.junit.Assert;

import java.io.IOException;
import java.io.StringReader;
Expand Down Expand Up @@ -134,15 +133,10 @@ public void testStandardHtmlStripAnalyzerDeprecationError() throws IOException {
.build();

IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) {
IndexAnalyzers analyzers = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).indexAnalyzers;
Assert.fail("[standard_html_strip] is created");
} catch (IllegalArgumentException iae) {
assertEquals(iae.getMessage(), "[standard_html_strip] analyzer is not supported for new indices, " +
"use a custom analyzer using [standard] tokenizer and [html_strip] char_filter, plus [lowercase] filter");
} catch (Exception e) {
fail("expected IAE");
}
CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin();
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> createTestAnalysis(idxSettings, settings, commonAnalysisPlugin));
assertEquals("[standard_html_strip] analyzer is not supported for new indices, " +
"use a custom analyzer using [standard] tokenizer and [html_strip] char_filter, plus [lowercase] filter", ex.getMessage());
}

/**
Expand All @@ -151,7 +145,7 @@ public void testStandardHtmlStripAnalyzerDeprecationError() throws IOException {
public void testStandardHtmlStripAnalyzerDeprecationWarning() throws IOException {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put(IndexMetaData.SETTING_VERSION_CREATED,
VersionUtils.randomVersionBetween(random(), Version.V_6_5_0, Version.V_6_6_0))
VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.V_6_6_0))
.put("index.analysis.analyzer.custom_analyzer.type", "standard_html_strip")
.putList("index.analysis.analyzer.custom_analyzer.stopwords", "a", "b")
.build();
Expand All @@ -166,24 +160,4 @@ public void testStandardHtmlStripAnalyzerDeprecationWarning() throws IOException
"replace it with a custom analyzer using [standard] tokenizer and [html_strip] char_filter, plus [lowercase] filter");
}
}

/**
* Check that the deprecated analyzer name "standard_html_strip" does NOT issue a deprecation warning for indices created before 6.4.0
*/
public void testStandardHtmlStripAnalyzerNoDeprecationPre6_5() throws IOException {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put(IndexMetaData.SETTING_VERSION_CREATED,
VersionUtils.randomVersionBetween(random(), Version.V_6_0_0_alpha1, Version.V_6_4_0))
.put("index.analysis.analyzer.custom_analyzer.type", "standard_html_strip")
.putList("index.analysis.analyzer.custom_analyzer.stopwords", "a", "b")
.build();

IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) {
IndexAnalyzers analyzers = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).indexAnalyzers;
Analyzer analyzer = analyzers.get("custom_analyzer");

assertNotNull(((NamedAnalyzer) analyzer).analyzer());
}
}
}

0 comments on commit d57aff6

Please sign in to comment.