TermsFilter tf=new TermsFilter();
NodeList nl = e.getElementsByTagName("Field");
for(int i=0;i<nl.getLength();i++)
{
Element fieldElem=(Element) nl.item(i);
String fieldName=DOMUtils.getAttributeWithInheritance(fieldElem,"fieldName");
if(fieldName==null)
{
throw new ParserException("TermsFilter missing \"fieldName\" element");
}
String text=DOMUtils.getText(fieldElem).trim();
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
{
term=term.createTerm(token.termText()); //create from previous to save fieldName.intern overhead
}
tf.addTerm(term);
token=ts.next();
}
}
catch(IOException ioe)
{
throw new RuntimeException("Error constructing terms from index:"+ioe);
}
}
return tf;