Override normalize for the PatternReplaceFilterFactory

This commit is contained in:
Dainius Jocas 2023-10-02 00:22:50 +03:00
parent 3cb71436a7
commit d2105eb86b
2 changed files with 17 additions and 0 deletions

View File

@ -67,4 +67,9 @@ public class PatternReplaceFilterFactory extends TokenFilterFactory {
public PatternReplaceFilter create(TokenStream input) {
return new PatternReplaceFilter(input, pattern, replacement, replaceAll);
}
@Override
public TokenStream normalize(TokenStream input) {
return create(input);
}
}

View File

@ -18,6 +18,8 @@ package org.apache.lucene.analysis.pattern;
import java.io.Reader;
import java.io.StringReader;
import org.apache.lucene.analysis.TokenFilterFactory;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.tests.analysis.BaseTokenStreamFactoryTestCase;
@ -44,4 +46,14 @@ public class TestPatternReplaceFilterFactory extends BaseTokenStreamFactoryTestC
});
assertTrue(expected.getMessage().contains("Unknown parameters"));
}
/** Test that normalizer is working */
public void testNormalize() throws Exception {
Reader reader = new StringReader("123");
TokenStream stream = whitespaceMockTokenizer(reader);
TokenFilterFactory factory =
tokenFilterFactory("PatternReplace", "pattern", "(-?\\d+)", "replacement", "000$1");
stream = factory.normalize(stream);
assertTokenStreamContents(stream, new String[] {"000123"});
}
}