Bill-hbrhbr commented on code in PR #13003: URL: https://github.com/apache/pinot/pull/13003#discussion_r1585546015
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/TextIndexUtils.java: ########## @@ -108,10 +113,140 @@ private static List<String> parseEntryAsString(@Nullable Map<String, String> col .collect(Collectors.toList()); } - public static Analyzer getAnalyzerFromClassName(String luceneAnalyzerClass) - throws ReflectiveOperationException { - // Support instantiation with default constructor for now unless customized - return (Analyzer) Class.forName(luceneAnalyzerClass).getConstructor().newInstance(); + public static Analyzer getAnalyzer(TextIndexConfig config) throws ReflectiveOperationException { + String luceneAnalyzerClassName = config.getLuceneAnalyzerClass(); + List<String> luceneAnalyzerClassArgs = config.getLuceneAnalyzerClassArgs(); + List<String> luceneAnalyzerClassArgsTypes = config.getLuceneAnalyzerClassArgTypes(); Review Comment: ```suggestion List<String> luceneAnalyzerClassArgTypes = config.getLuceneAnalyzerClassArgTypes(); ``` ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/TextIndexUtils.java: ########## @@ -108,10 +113,140 @@ private static List<String> parseEntryAsString(@Nullable Map<String, String> col .collect(Collectors.toList()); } - public static Analyzer getAnalyzerFromClassName(String luceneAnalyzerClass) - throws ReflectiveOperationException { - // Support instantiation with default constructor for now unless customized - return (Analyzer) Class.forName(luceneAnalyzerClass).getConstructor().newInstance(); + public static Analyzer getAnalyzer(TextIndexConfig config) throws ReflectiveOperationException { + String luceneAnalyzerClassName = config.getLuceneAnalyzerClass(); + List<String> luceneAnalyzerClassArgs = config.getLuceneAnalyzerClassArgs(); + List<String> luceneAnalyzerClassArgsTypes = config.getLuceneAnalyzerClassArgTypes(); + + if (null == luceneAnalyzerClassName || luceneAnalyzerClassName.isEmpty() + || (luceneAnalyzerClassName.equals(StandardAnalyzer.class.getName()) + && luceneAnalyzerClassArgs.isEmpty() && luceneAnalyzerClassArgsTypes.isEmpty())) { + // When there is no analyzer defined, or when StandardAnalyzer (default) is used without arguments, + // use existing logic to obtain an instance of StandardAnalyzer with customized stop words + return TextIndexUtils.getStandardAnalyzerWithCustomizedStopWords( + config.getStopWordsInclude(), config.getStopWordsExclude()); + } else { + // Custom analyzer + custom configs via reflection + if (luceneAnalyzerClassArgs.size() != luceneAnalyzerClassArgsTypes.size()) { + throw new ReflectiveOperationException("Mismatch of the number of analyzer arguments and arguments types."); + } + + // Generate args type list + List<Class<?>> argClasses = new ArrayList<>(); + for (String argType : luceneAnalyzerClassArgsTypes) { Review Comment: ```suggestion for (String argType : luceneAnalyzerClassArgTypes) { ``` ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/TextIndexUtils.java: ########## @@ -108,10 +113,140 @@ private static List<String> parseEntryAsString(@Nullable Map<String, String> col .collect(Collectors.toList()); } - public static Analyzer getAnalyzerFromClassName(String luceneAnalyzerClass) - throws ReflectiveOperationException { - // Support instantiation with default constructor for now unless customized - return (Analyzer) Class.forName(luceneAnalyzerClass).getConstructor().newInstance(); + public static Analyzer getAnalyzer(TextIndexConfig config) throws ReflectiveOperationException { + String luceneAnalyzerClassName = config.getLuceneAnalyzerClass(); + List<String> luceneAnalyzerClassArgs = config.getLuceneAnalyzerClassArgs(); + List<String> luceneAnalyzerClassArgsTypes = config.getLuceneAnalyzerClassArgTypes(); + + if (null == luceneAnalyzerClassName || luceneAnalyzerClassName.isEmpty() + || (luceneAnalyzerClassName.equals(StandardAnalyzer.class.getName()) + && luceneAnalyzerClassArgs.isEmpty() && luceneAnalyzerClassArgsTypes.isEmpty())) { + // When there is no analyzer defined, or when StandardAnalyzer (default) is used without arguments, + // use existing logic to obtain an instance of StandardAnalyzer with customized stop words + return TextIndexUtils.getStandardAnalyzerWithCustomizedStopWords( + config.getStopWordsInclude(), config.getStopWordsExclude()); + } else { + // Custom analyzer + custom configs via reflection + if (luceneAnalyzerClassArgs.size() != luceneAnalyzerClassArgsTypes.size()) { Review Comment: ```suggestion if (luceneAnalyzerClassArgs.size() != luceneAnalyzerClassArgTypes.size()) { ``` ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/store/TextIndexUtils.java: ########## @@ -108,10 +113,140 @@ private static List<String> parseEntryAsString(@Nullable Map<String, String> col .collect(Collectors.toList()); } - public static Analyzer getAnalyzerFromClassName(String luceneAnalyzerClass) - throws ReflectiveOperationException { - // Support instantiation with default constructor for now unless customized - return (Analyzer) Class.forName(luceneAnalyzerClass).getConstructor().newInstance(); + public static Analyzer getAnalyzer(TextIndexConfig config) throws ReflectiveOperationException { + String luceneAnalyzerClassName = config.getLuceneAnalyzerClass(); + List<String> luceneAnalyzerClassArgs = config.getLuceneAnalyzerClassArgs(); + List<String> luceneAnalyzerClassArgsTypes = config.getLuceneAnalyzerClassArgTypes(); + + if (null == luceneAnalyzerClassName || luceneAnalyzerClassName.isEmpty() + || (luceneAnalyzerClassName.equals(StandardAnalyzer.class.getName()) + && luceneAnalyzerClassArgs.isEmpty() && luceneAnalyzerClassArgsTypes.isEmpty())) { Review Comment: ```suggestion && luceneAnalyzerClassArgs.isEmpty() && luceneAnalyzerClassArgTypes.isEmpty())) { ``` -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org