Skip to content

Commit 49acc92

Browse files
committed
Remove version dependent logic from ShingleTokenFilterFactory
This commit removes conditionals for logic that no longer needs to be version dependent, in that all indices in the cluster will match such condition. Relates to elastic#27211,elastic#34331
1 parent 54435b1 commit 49acc92

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

server/src/main/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactory.java

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,35 @@
1111

1212
import org.apache.lucene.analysis.TokenStream;
1313
import org.apache.lucene.analysis.shingle.ShingleFilter;
14-
import org.elasticsearch.common.logging.DeprecationCategory;
15-
import org.elasticsearch.common.logging.DeprecationLogger;
1614
import org.elasticsearch.common.settings.Settings;
1715
import org.elasticsearch.env.Environment;
1816
import org.elasticsearch.index.IndexSettings;
19-
import org.elasticsearch.index.IndexVersions;
2017
import org.elasticsearch.lucene.analysis.miscellaneous.DisableGraphAttribute;
2118

2219
public class ShingleTokenFilterFactory extends AbstractTokenFilterFactory {
2320

24-
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(ShingleTokenFilterFactory.class);
25-
2621
private final Factory factory;
2722

28-
private final IndexSettings indexSettings;
29-
3023
public ShingleTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
3124
super(name, settings);
32-
this.indexSettings = indexSettings;
3325
int maxAllowedShingleDiff = indexSettings.getMaxShingleDiff();
3426
Integer maxShingleSize = settings.getAsInt("max_shingle_size", ShingleFilter.DEFAULT_MAX_SHINGLE_SIZE);
3527
Integer minShingleSize = settings.getAsInt("min_shingle_size", ShingleFilter.DEFAULT_MIN_SHINGLE_SIZE);
3628
Boolean outputUnigrams = settings.getAsBoolean("output_unigrams", true);
3729

3830
int shingleDiff = maxShingleSize - minShingleSize + (outputUnigrams ? 1 : 0);
3931
if (shingleDiff > maxAllowedShingleDiff) {
40-
if (indexSettings.getIndexVersionCreated().onOrAfter(IndexVersions.V_7_0_0)) {
41-
throw new IllegalArgumentException(
42-
"In Shingle TokenFilter the difference between max_shingle_size and min_shingle_size (and +1 if outputting unigrams)"
43-
+ " must be less than or equal to: ["
44-
+ maxAllowedShingleDiff
45-
+ "] but was ["
46-
+ shingleDiff
47-
+ "]. This limit"
48-
+ " can be set by changing the ["
49-
+ IndexSettings.MAX_SHINGLE_DIFF_SETTING.getKey()
50-
+ "] index level setting."
51-
);
52-
} else {
53-
DEPRECATION_LOGGER.warn(
54-
DeprecationCategory.ANALYSIS,
55-
"excessive_shingle_diff",
56-
"Deprecated big difference between maxShingleSize and minShingleSize"
57-
+ " in Shingle TokenFilter, expected difference must be less than or equal to: ["
58-
+ maxAllowedShingleDiff
59-
+ "]"
60-
);
61-
}
32+
throw new IllegalArgumentException(
33+
"In Shingle TokenFilter the difference between max_shingle_size and min_shingle_size (and +1 if outputting unigrams)"
34+
+ " must be less than or equal to: ["
35+
+ maxAllowedShingleDiff
36+
+ "] but was ["
37+
+ shingleDiff
38+
+ "]. This limit"
39+
+ " can be set by changing the ["
40+
+ IndexSettings.MAX_SHINGLE_DIFF_SETTING.getKey()
41+
+ "] index level setting."
42+
);
6243
}
6344

6445
Boolean outputUnigramsIfNoShingles = settings.getAsBoolean("output_unigrams_if_no_shingles", false);
@@ -82,17 +63,7 @@ public TokenStream create(TokenStream tokenStream) {
8263

8364
@Override
8465
public TokenFilterFactory getSynonymFilter() {
85-
if (indexSettings.getIndexVersionCreated().onOrAfter(IndexVersions.V_7_0_0)) {
86-
throw new IllegalArgumentException("Token filter [" + name() + "] cannot be used to parse synonyms");
87-
} else {
88-
DEPRECATION_LOGGER.warn(
89-
DeprecationCategory.ANALYSIS,
90-
"synonym_tokenfilters",
91-
"Token filter " + name() + "] will not be usable to parse synonym after v7.0"
92-
);
93-
}
94-
return this;
95-
66+
throw new IllegalArgumentException("Token filter [" + name() + "] cannot be used to parse synonyms");
9667
}
9768

9869
public Factory getInnerFactory() {
@@ -109,7 +80,7 @@ public static final class Factory implements TokenFilterFactory {
10980
private final String tokenSeparator;
11081
private final String fillerToken;
11182

112-
private int minShingleSize;
83+
private final int minShingleSize;
11384

11485
private final String name;
11586

0 commit comments

Comments
 (0)