rmuir commented on code in PR #16722:
URL: https://github.com/apache/lucene/pull/16722#discussion_r4117195192


##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/th/ThaiTokenizer.java:
##########
@@ -61,17 +70,55 @@ public class ThaiTokenizer extends SegmentingTokenizerBase {
 
   /** Creates a new ThaiTokenizer */
   public ThaiTokenizer() {
-    this(DEFAULT_TOKEN_ATTRIBUTE_FACTORY);
+    this(DEFAULT_TOKEN_ATTRIBUTE_FACTORY, null);
+  }
+
+  /**
+   * Creates a new ThaiTokenizer with a user dictionary.
+   *
+   * @param userDictionary custom dictionary of words, or null for default 
dictionary only
+   */
+  public ThaiTokenizer(CharArraySet userDictionary) {
+    this(DEFAULT_TOKEN_ATTRIBUTE_FACTORY, userDictionary);
   }
 
   /** Creates a new ThaiTokenizer, supplying the AttributeFactory */
   public ThaiTokenizer(AttributeFactory factory) {
+    this(factory, null);
+  }
+
+  /**
+   * Creates a new ThaiTokenizer, supplying the AttributeFactory and user 
dictionary.
+   *
+   * @param factory AttributeFactory to use
+   * @param userDictionary custom dictionary of words, or null for default 
dictionary only
+   */
+  public ThaiTokenizer(AttributeFactory factory, CharArraySet userDictionary) {
     super(factory, (BreakIterator) sentenceProto.clone());
     if (!DBBI_AVAILABLE) {
       throw new UnsupportedOperationException(
           "This JRE does not have support for Thai segmentation");
     }
     wordBreaker = (BreakIterator) proto.clone();
+    this.userDictionary = userDictionary;
+    if (userDictionary != null && !userDictionary.isEmpty()) {
+      int minLen = Integer.MAX_VALUE;
+      int maxLen = 0;
+      for (Object obj : userDictionary) {
+        int length = (obj instanceof char[]) ? ((char[]) obj).length : 
obj.toString().length();
+        if (length < minLen) {
+          minLen = length;
+        }
+        if (length > maxLen) {
+          maxLen = length;
+        }

Review Comment:
   I think we can simplify this a bit to remove some conditionals. The 
`CharArraySet` always returns an Iterator over a `char[]`, and I think using 
min and max functions helps readability?
   
   ```suggestion
           int length = ((char[]) obj).length;
           minLen = Math.min(minLen, length);
           maxLen = Math.max(maxLen, length);
   ```



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