-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate nGram
and edgeNGram
names for ngram filters
#30209
Merged
cbuescher
merged 6 commits into
elastic:master
from
cbuescher:deprecate-nGram-edgeNGram
May 17, 2018
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e808530
Deprecate `nGram` and `edgeNGram` names for ngram filters (#27429)
875ad00
Merge branch 'master' into deprecate-nGram-edgeNGram
0de4aac
Renamed test class
b836759
corrected typo
6db2205
Merge branch 'master' into deprecate-nGram-edgeNGram
a89b604
Merge branch 'master' into deprecate-nGram-edgeNGram
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...sis-common/src/test/java/org/elasticsearch/analysis/common/CommonAnalysisPluginTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.analysis.common; | ||
|
||
import org.apache.lucene.analysis.MockTokenizer; | ||
import org.apache.lucene.analysis.Tokenizer; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.analysis.TokenFilterFactory; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.IndexSettingsModule; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.Map; | ||
|
||
public class CommonAnalysisPluginTests extends ESTestCase { | ||
|
||
/** | ||
* Check that the deprecated name "nGram" issues a deprecation warning for indices created since 6.3.0 | ||
*/ | ||
public void testNGramDeprecationWarning() throws IOException { | ||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) | ||
.put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_6_4_0, Version.CURRENT)) | ||
.build(); | ||
|
||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); | ||
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) { | ||
Map<String, TokenFilterFactory> tokenFilters = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).tokenFilter; | ||
TokenFilterFactory tokenFilterFactory = tokenFilters.get("nGram"); | ||
Tokenizer tokenizer = new MockTokenizer(); | ||
tokenizer.setReader(new StringReader("foo bar")); | ||
assertNotNull(tokenFilterFactory.create(tokenizer)); | ||
assertWarnings( | ||
"The [nGram] token filter name is deprecated and will be removed in a future version. " | ||
+ "Please change the filter name to [ngram] instead."); | ||
} | ||
} | ||
|
||
/** | ||
* Check that the deprecated name "nGram" does NOT issues a deprecation warning for indices created before 6.4.0 | ||
*/ | ||
public void testNGramNoDeprecationWarningPre6_4() throws IOException { | ||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) | ||
.put(IndexMetaData.SETTING_VERSION_CREATED, | ||
VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.V_6_3_0)) | ||
.build(); | ||
|
||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); | ||
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) { | ||
Map<String, TokenFilterFactory> tokenFilters = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).tokenFilter; | ||
TokenFilterFactory tokenFilterFactory = tokenFilters.get("nGram"); | ||
Tokenizer tokenizer = new MockTokenizer(); | ||
tokenizer.setReader(new StringReader("foo bar")); | ||
assertNotNull(tokenFilterFactory.create(tokenizer)); | ||
} | ||
} | ||
|
||
/** | ||
* Check that the deprecated name "edgeNGram" issues a deprecation warning for indices created since 6.3.0 | ||
*/ | ||
public void testEdgeNGramDeprecationWarning() throws IOException { | ||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) | ||
.put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_6_4_0, Version.CURRENT)) | ||
.build(); | ||
|
||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); | ||
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) { | ||
Map<String, TokenFilterFactory> tokenFilters = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).tokenFilter; | ||
TokenFilterFactory tokenFilterFactory = tokenFilters.get("edgeNGram"); | ||
Tokenizer tokenizer = new MockTokenizer(); | ||
tokenizer.setReader(new StringReader("foo bar")); | ||
assertNotNull(tokenFilterFactory.create(tokenizer)); | ||
assertWarnings( | ||
"The [edgeNGram] token filter name is deprecated and will be removed in a future version. " | ||
+ "Please change the filter name to [edge_ngram] instead."); | ||
} | ||
} | ||
|
||
/** | ||
* Check that the deprecated name "edgeNGram" does NOT issues a deprecation warning for indices created before 6.4.0 | ||
*/ | ||
public void testEdgeNGramNoDeprecationWarningPre6_4() throws IOException { | ||
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) | ||
.put(IndexMetaData.SETTING_VERSION_CREATED, | ||
VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.V_6_3_0)) | ||
.build(); | ||
|
||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); | ||
try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) { | ||
Map<String, TokenFilterFactory> tokenFilters = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).tokenFilter; | ||
TokenFilterFactory tokenFilterFactory = tokenFilters.get("edgeNGram"); | ||
Tokenizer tokenizer = new MockTokenizer(); | ||
tokenizer.setReader(new StringReader("foo bar")); | ||
assertNotNull(tokenFilterFactory.create(tokenizer)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/esgeNgram/edgeNgram/