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


##########
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:
   I have an idea. For Solr I will make the default dependent on the 
matchVersion. Codepoints starting with Lucene 10.5 if specified in Solr schema. 
Old indexes and schemas then use old behaviour. While new versions and indexes 
use codepoints as default.



-- 
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