FileDocCategorySizeDatePackage
TermsFilterBuilder.javaAPI DocApache Lucene 2.2.02557Sat Jun 16 22:21:00 BST 2007org.apache.lucene.xmlparser.builders

TermsFilterBuilder

public class TermsFilterBuilder extends Object implements org.apache.lucene.xmlparser.FilterBuilder
author
maharwood

Fields Summary
Analyzer
analyzer
Constructors Summary
public TermsFilterBuilder(Analyzer analyzer)

param
analyzer

		this.analyzer = analyzer;
	
Methods Summary
public org.apache.lucene.search.FiltergetFilter(org.w3c.dom.Element e)

		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;