uschindler commented on code in PR #15900:
URL: https://github.com/apache/lucene/pull/15900#discussion_r3032867492


##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/TruncateTokenFilterFactory.java:
##########
@@ -45,15 +58,34 @@ public class TruncateTokenFilterFactory extends 
TokenFilterFactory {
   /** SPI name */
   public static final String NAME = "truncate";
 
-  public static final String PREFIX_LENGTH_KEY = "prefixLength";
-  private final int prefixLength;
+  @Deprecated public static final String PREFIX_LENGTH_KEY = "prefixLength";
+  public static final String TRUNCATE_AFTER_CODEPOINTS_KEY = 
"truncateAfterCodePoints";
+  public static final String TRUNCATE_AFTER_CHARS_KEY = "truncateAfterChars";
+
+  private static final Map<String, BiFunction<TokenStream, Integer, 
TruncateTokenFilter>>
+      PARAM_MAPPING =
+          Map.of(
+              TRUNCATE_AFTER_CODEPOINTS_KEY, 
TruncateTokenFilter::truncateAfterCodePoints,
+              TRUNCATE_AFTER_CHARS_KEY, 
TruncateTokenFilter::truncateAfterChars,
+              PREFIX_LENGTH_KEY, TruncateTokenFilter::truncateAfterChars);
+
+  private final int truncateAfter;
+  private final BiFunction<TokenStream, Integer, TruncateTokenFilter> factory;
 
   public TruncateTokenFilterFactory(Map<String, String> args) {
     super(args);
-    prefixLength = Integer.parseInt(get(args, PREFIX_LENGTH_KEY, "5"));
-    if (prefixLength < 1)
+    var avail = 
PARAM_MAPPING.keySet().stream().filter(args::containsKey).toList();
+    if (avail.size() > 1) {
+      throw new IllegalArgumentException(
+          "Can only give one of the following parameters: " + 
PARAM_MAPPING.keySet());
+    }
+    String param = avail.stream().findFirst().orElse(PREFIX_LENGTH_KEY);

Review Comment:
   or should the default (at least in 11.x use codepoints. Now its backwards 
compatible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to