gus-asf commented on a change in pull request #1995: URL: https://github.com/apache/lucene-solr/pull/1995#discussion_r510116825
########## File path: lucene/analysis/common/src/java/org/apache/lucene/analysis/pattern/PatternTypingFilterFactory.java ########## @@ -0,0 +1,120 @@ +/* + * 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 java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +import org.apache.lucene.analysis.TokenFilterFactory; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.util.ResourceLoader; +import org.apache.lucene.util.ResourceLoaderAware; + + +/** + * Provides a filter that will analyze tokens with the analyzer from an arbitrary field type. By itself this + * filter is not very useful. Normally it is combined with a filter that reacts to types or flags. + * + * <pre class="prettyprint" > + * <fieldType name="text_taf" class="solr.TextField" positionIncrementGap="100"> + * <analyzer> + * <tokenizer class="solr.WhitespaceTokenizerFactory"/> + * <filter class="com.example.PatternTypingFilter" patternFile="patterns.txt"/> + * <filter class="solr.TokenAnalyzerFilter" asType="text_en" preserveType="true"/> + * <filter class="solr.TypeAsSynonymFilterFactory" prefix="__TAS__" + * ignore="word,&lt;ALPHANUM&gt;,&lt;NUM&gt;,&lt;SOUTHEAST_ASIAN&gt;,&lt;IDEOGRAPHIC&gt;,&lt;HIRAGANA&gt;,&lt;KATAKANA&gt;,&lt;HANGUL&gt;,&lt;EMOJI&gt;"/> + * </analyzer> + * </fieldType></pre> + * <p> + * Note that a configuration such as above may interfere with multi-word synonyms. The patterns file has the format: + * <pre> + * (flags) (pattern) ::: (replacement) + * </pre> + * Therefore to set the first 2 flag bits on the original token matching 401k or 401(k) and adding a type of + * 'legal2_401_k' whenever either one is encountered one would use: + * <pre> + * 3 (\d+)\(?([a-z])\)? ::: legal2_$1_$2 + * </pre> + * Note that the number indicating the flag bits to set must not have leading spaces and be followed by a single + * space, and must be 0 if no flags should be set. The flags number should not contain commas or a decimal point. + * Lines for which the first character is <code>#</code> will be ignored as comments. Does not support producing + * a synonym textually identical to the original term. + * + * @lucene.spi {@value #NAME} + * @since 8.8 + */ +public class PatternTypingFilterFactory extends TokenFilterFactory implements ResourceLoaderAware { + + /** + * SPI name + */ + public static final String NAME = "patternTyping"; + + private final String patternFile; + // todo, perhaps this could be turned into an FST (wanted: regex FST with capturing groups in java) + private final LinkedHashMap<Pattern, String> patterns = new LinkedHashMap<>(); + private final Map<Pattern, Integer> flags = new HashMap<>(); + + /** + * Creates a new KeepWordFilterFactory Review comment: thx ---------------------------------------------------------------- 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