|
@@ -23,10 +23,7 @@ import org.apache.lucene.analysis.Analyzer;
|
|
|
import org.apache.lucene.analysis.TokenStream;
|
|
|
import org.apache.lucene.analysis.Tokenizer;
|
|
|
import org.apache.lucene.analysis.ar.ArabicNormalizationFilter;
|
|
|
-import org.apache.lucene.analysis.core.KeywordAnalyzer;
|
|
|
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
|
|
|
-import org.apache.lucene.analysis.de.GermanAnalyzer;
|
|
|
-import org.apache.lucene.analysis.en.EnglishAnalyzer;
|
|
|
import org.apache.lucene.analysis.fa.PersianNormalizationFilter;
|
|
|
import org.apache.lucene.analysis.hunspell.Dictionary;
|
|
|
import org.apache.lucene.analysis.miscellaneous.KeywordRepeatFilter;
|
|
@@ -123,83 +120,6 @@ public class AnalysisModuleTests extends ModuleTestCase {
|
|
|
assertTokenFilter("arabic_normalization", ArabicNormalizationFilter.class);
|
|
|
}
|
|
|
|
|
|
- public void testAnalyzerAlias() throws IOException {
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put("index.analysis.analyzer.foobar.alias","default")
|
|
|
- .put("index.analysis.analyzer.foobar.type", "keyword")
|
|
|
- .put("index.analysis.analyzer.foobar_search.alias","default_search")
|
|
|
- .put("index.analysis.analyzer.foobar_search.type","english")
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- // analyzer aliases are only allowed in 2.x indices
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5))
|
|
|
- .build();
|
|
|
- AnalysisRegistry newRegistry = getNewRegistry(settings);
|
|
|
- IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings);
|
|
|
- assertThat(indexAnalyzers.get("default").analyzer(), is(instanceOf(KeywordAnalyzer.class)));
|
|
|
- assertThat(indexAnalyzers.get("default_search").analyzer(), is(instanceOf(EnglishAnalyzer.class)));
|
|
|
- assertWarnings("setting [index.analysis.analyzer.foobar.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.",
|
|
|
- "setting [index.analysis.analyzer.foobar_search.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.");
|
|
|
- }
|
|
|
-
|
|
|
- public void testAnalyzerAliasReferencesAlias() throws IOException {
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put("index.analysis.analyzer.foobar.alias","default")
|
|
|
- .put("index.analysis.analyzer.foobar.type", "german")
|
|
|
- .put("index.analysis.analyzer.foobar_search.alias","default_search")
|
|
|
- .put("index.analysis.analyzer.foobar_search.type", "default")
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- // analyzer aliases are only allowed in 2.x indices
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5))
|
|
|
- .build();
|
|
|
- AnalysisRegistry newRegistry = getNewRegistry(settings);
|
|
|
- IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings);
|
|
|
-
|
|
|
- assertThat(indexAnalyzers.get("default").analyzer(), is(instanceOf(GermanAnalyzer.class)));
|
|
|
- // analyzer types are bound early before we resolve aliases
|
|
|
- assertThat(indexAnalyzers.get("default_search").analyzer(), is(instanceOf(StandardAnalyzer.class)));
|
|
|
- assertWarnings("setting [index.analysis.analyzer.foobar.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.",
|
|
|
- "setting [index.analysis.analyzer.foobar_search.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.");
|
|
|
- }
|
|
|
-
|
|
|
- public void testAnalyzerAliasDefault() throws IOException {
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put("index.analysis.analyzer.foobar.alias","default")
|
|
|
- .put("index.analysis.analyzer.foobar.type", "keyword")
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- // analyzer aliases are only allowed in 2.x indices
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5))
|
|
|
- .build();
|
|
|
- AnalysisRegistry newRegistry = getNewRegistry(settings);
|
|
|
- IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings);
|
|
|
- assertThat(indexAnalyzers.get("default").analyzer(), is(instanceOf(KeywordAnalyzer.class)));
|
|
|
- assertThat(indexAnalyzers.get("default_search").analyzer(), is(instanceOf(KeywordAnalyzer.class)));
|
|
|
- assertWarnings("setting [index.analysis.analyzer.foobar.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.");
|
|
|
- }
|
|
|
-
|
|
|
- public void testAnalyzerAliasMoreThanOnce() throws IOException {
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put("index.analysis.analyzer.foobar.alias","default")
|
|
|
- .put("index.analysis.analyzer.foobar.type", "keyword")
|
|
|
- .put("index.analysis.analyzer.foobar1.alias","default")
|
|
|
- .put("index.analysis.analyzer.foobar1.type", "english")
|
|
|
- // analyzer aliases are only allowed in 2.x indices
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5))
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- .build();
|
|
|
- AnalysisRegistry newRegistry = getNewRegistry(settings);
|
|
|
- IllegalStateException ise = expectThrows(IllegalStateException.class, () -> getIndexAnalyzers(newRegistry, settings));
|
|
|
- assertEquals("alias [default] is already used by [foobar]", ise.getMessage());
|
|
|
- assertWarnings("setting [index.analysis.analyzer.foobar.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.",
|
|
|
- "setting [index.analysis.analyzer.foobar1.alias] is only allowed on index [test] because it was created before " +
|
|
|
- "5.x; analyzer aliases can no longer be created on new indices.");
|
|
|
- }
|
|
|
-
|
|
|
public void testAnalyzerAliasNotAllowedPost5x() throws IOException {
|
|
|
Settings settings = Settings.builder()
|
|
|
.put("index.analysis.analyzer.foobar.type", "standard")
|
|
@@ -218,7 +138,7 @@ public class AnalysisModuleTests extends ModuleTestCase {
|
|
|
Settings settings2 = Settings.builder()
|
|
|
.loadFromStream(yaml, getClass().getResourceAsStream(yaml))
|
|
|
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0)
|
|
|
+ .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_0_0)
|
|
|
.build();
|
|
|
AnalysisRegistry newRegistry = getNewRegistry(settings2);
|
|
|
IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings2);
|
|
@@ -231,8 +151,10 @@ public class AnalysisModuleTests extends ModuleTestCase {
|
|
|
|
|
|
// analysis service has the expected version
|
|
|
assertThat(indexAnalyzers.get("standard").analyzer(), is(instanceOf(StandardAnalyzer.class)));
|
|
|
- assertEquals(Version.V_2_0_0.luceneVersion, indexAnalyzers.get("standard").analyzer().getVersion());
|
|
|
- assertEquals(Version.V_2_0_0.luceneVersion, indexAnalyzers.get("thai").analyzer().getVersion());
|
|
|
+ assertEquals(Version.V_5_0_0.luceneVersion,
|
|
|
+ indexAnalyzers.get("standard").analyzer().getVersion());
|
|
|
+ assertEquals(Version.V_5_0_0.luceneVersion,
|
|
|
+ indexAnalyzers.get("thai").analyzer().getVersion());
|
|
|
|
|
|
assertThat(indexAnalyzers.get("custom7").analyzer(), is(instanceOf(StandardAnalyzer.class)));
|
|
|
assertEquals(org.apache.lucene.util.Version.fromBits(3,6,0), indexAnalyzers.get("custom7").analyzer().getVersion());
|
|
@@ -355,40 +277,6 @@ public class AnalysisModuleTests extends ModuleTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void testUnderscoreInAnalyzerNameAlias() throws IOException {
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put("index.analysis.analyzer.valid_name.tokenizer", "keyword")
|
|
|
- .put("index.analysis.analyzer.valid_name.alias", "_invalid_name")
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- // analyzer aliases are only allowed for 2.x indices
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_5))
|
|
|
- .build();
|
|
|
- try {
|
|
|
- getIndexAnalyzers(settings);
|
|
|
- fail("This should fail with IllegalArgumentException because the analyzers alias starts with _");
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- assertThat(e.getMessage(), equalTo("analyzer name must not start with '_'. got \"_invalid_name\""));
|
|
|
- }
|
|
|
- assertWarnings("setting [index.analysis.analyzer.valid_name.alias] is only allowed on index [test] because it was " +
|
|
|
- "created before 5.x; analyzer aliases can no longer be created on new indices.");
|
|
|
- }
|
|
|
-
|
|
|
- public void testDeprecatedPositionOffsetGap() throws IOException {
|
|
|
- Settings settings = Settings.builder()
|
|
|
- .put("index.analysis.analyzer.custom.tokenizer", "standard")
|
|
|
- .put("index.analysis.analyzer.custom.position_offset_gap", "128")
|
|
|
- .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
|
|
- .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
|
|
- .build();
|
|
|
- try {
|
|
|
- getIndexAnalyzers(settings);
|
|
|
- fail("Analyzer should fail if it has position_offset_gap");
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
- assertThat(e.getMessage(), equalTo("Option [position_offset_gap] in Custom Analyzer [custom] " +
|
|
|
- "has been renamed, please use [position_increment_gap] instead."));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void testRegisterHunspellDictionary() throws Exception {
|
|
|
Settings settings = Settings.builder()
|
|
|
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|