Apache Lucene open-source search software
TruncateTokenFilterFactory now accepts lengths > 127 (#12507)
asubbu900e96b9cd8c12
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/TruncateTokenFilterFactory.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/TruncateTokenFilterFactory.javaindex 3c508b94322..ba57a675b6f 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/TruncateTokenFilterFactory.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/TruncateTokenFilterFactory.java@@ -46,11 +46,11 @@ public class TruncateTokenFilterFactory extends TokenFilterFactory {public static final String NAME = "truncate";public static final String PREFIX_LENGTH_KEY = "prefixLength";- private final byte prefixLength;+ private final int prefixLength;public TruncateTokenFilterFactory(Map<String, String> args) {super(args);- prefixLength = Byte.parseByte(get(args, PREFIX_LENGTH_KEY, "5"));+ prefixLength = Integer.parseInt(get(args, PREFIX_LENGTH_KEY, "5"));if (prefixLength < 1)throw new IllegalArgumentException(PREFIX_LENGTH_KEY + " parameter must be a positive number: " + prefixLength);diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestTruncateTokenFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestTruncateTokenFilterFactory.javaindex 2fed6c2ae21..f537b93a156 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestTruncateTokenFilterFactory.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestTruncateTokenFilterFactory.java@@ -68,4 +68,23 @@ public class TestTruncateTokenFilterFactory extends BaseTokenStreamFactoryTestCaTruncateTokenFilterFactory.PREFIX_LENGTH_KEY+ " parameter must be a positive number: -5"));}++ /** Test that takes length greater than byte limit accepts it */+ public void testLengthGreaterThanByteLimitArgument() throws Exception {+ Reader reader =+ new StringReader(+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw128characters From here");+ TokenStream stream = new MockTokenizer(MockTokenizer.WHITESPACE, false);+ ((Tokenizer) stream).setReader(reader);+ stream =+ tokenFilterFactory("Truncate", TruncateTokenFilterFactory.PREFIX_LENGTH_KEY, "128")+ .create(stream);+ assertTokenStreamContents(+ stream,+ new String[] {+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw1",+ "From",+ "here"+ });+ }}