uschindler commented on a change in pull request #1995: URL: https://github.com/apache/lucene-solr/pull/1995#discussion_r510868759
########## File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/pattern/PatternTypingFilter.java ########## @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.lucene.analysis.pattern; + +import org.apache.lucene.analysis.TokenFilter; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; +import org.apache.lucene.analysis.tokenattributes.FlagsAttribute; +import org.apache.lucene.analysis.tokenattributes.TypeAttribute; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Set a type attribute to a parameterized value when tokens are matched by any of a several regex patterns. The + * value set in the type attribute is parameterized with the match groups of the regex used for matching. + * In combination with TypeAsSynonymFilter and DropIfFlagged filter this can supply complex synonym patterns + * that are protected from subsequent analysis, and optionally drop the original term based on the flag + * set in this filter. See {@link PatternTypingFilterFactory} for full documentation. + * + * @see PatternTypingFilterFactory + * @since 8.8.0 + */ +public class PatternTypingFilter extends TokenFilter { + + private final Map<Pattern, Map.Entry<String, Integer>> replacementAndFlagByPattern; + private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); + private final FlagsAttribute flagAtt = addAttribute(FlagsAttribute.class); + private final TypeAttribute typeAtt = addAttribute(TypeAttribute.class); + + public PatternTypingFilter(TokenStream input, LinkedHashMap<Pattern, Map.Entry<String, Integer>> replacementAndFlagByPattern) { Review comment: Explicitely saying LinkedHashMap sounds strange. I know the list must be sorted, so it's more a list. I liked it use a <Pattern,String,Integer> record. This would be a classical exple of the new Java 6 record types! This is a public API, any client code may call this - also non-Solr users. So maybe the constructor argument should be `a List<PatternTypingRule>` (a new class, which may actually be a Record in Java 16/17). ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org