TermsFilter tf = new TermsFilter();
String text = DOMUtils.getNonBlankTextOrFail(e);
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
try
{
Token token = ts.next();
Term term = null;
while (token != null)
{
if (term == null)
{
term = new Term(fieldName, token.termText());
} else
{
// create from previous to save fieldName.intern overhead
term = term.createTerm(token.termText());
}
tf.addTerm(term);
token = ts.next();
}
}
catch (IOException ioe)
{
throw new RuntimeException("Error constructing terms from index:"
+ ioe);
}
return tf;