use of org.apache.lucene.util.AttributeFactory in project lucene-solr by apache.
the class FieldAnalysisRequestHandlerTest method testCustomAttribute.
//See SOLR-8460
@Test
public void testCustomAttribute() throws Exception {
FieldAnalysisRequest request = new FieldAnalysisRequest();
request.addFieldType("skutype1");
request.setFieldValue("hi, 3456-12 a Test");
request.setShowMatch(false);
FieldType fieldType = new TextField();
Analyzer analyzer = new TokenizerChain(new TokenizerFactory(Collections.emptyMap()) {
@Override
public Tokenizer create(AttributeFactory factory) {
return new CustomTokenizer(factory);
}
}, new TokenFilterFactory[] { new TokenFilterFactory(Collections.emptyMap()) {
@Override
public TokenStream create(TokenStream input) {
return new CustomTokenFilter(input);
}
} });
fieldType.setIndexAnalyzer(analyzer);
NamedList<NamedList> result = handler.analyzeValues(request, fieldType, "fieldNameUnused");
// just test that we see "900" in the flags attribute here
List<NamedList> tokenInfoList = (List<NamedList>) result.findRecursive("index", CustomTokenFilter.class.getName());
// '1' from CustomTokenFilter plus 900 from CustomFlagsAttributeImpl.
assertEquals(901, tokenInfoList.get(0).get("org.apache.lucene.analysis.tokenattributes.FlagsAttribute#flags"));
}
Aggregations