mirror of https://github.com/apache/lucene.git
Override normalize for the PatternReplaceFilterFactory
This commit is contained in:
parent
3cb71436a7
commit
d2105eb86b
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue