FileDocCategorySizeDatePackage
BooleanQueryBuilder.javaAPI DocApache Lucene 2.0.02026Fri May 26 09:53:50 BST 2006org.apache.lucene.xmlparser.builders

BooleanQueryBuilder

public class BooleanQueryBuilder extends Object implements org.apache.lucene.xmlparser.QueryBuilder
author
maharwood

Fields Summary
private org.apache.lucene.xmlparser.QueryBuilder
factory
Constructors Summary
public BooleanQueryBuilder(org.apache.lucene.xmlparser.QueryBuilder factory)

		this.factory=factory;
	
Methods Summary
static org.apache.lucene.search.BooleanClause$OccurgetOccursValue(org.w3c.dom.Element clauseElem)

		String occs=clauseElem.getAttribute("occurs");
		BooleanClause.Occur occurs=BooleanClause.Occur.SHOULD;
		if("must".equalsIgnoreCase(occs))
		{
			occurs=BooleanClause.Occur.MUST;
		}
		else
		{
			if("mustNot".equalsIgnoreCase(occs))
			{
				occurs=BooleanClause.Occur.MUST_NOT;
			}			
			else
			{
				if(("should".equalsIgnoreCase(occs))||("".equals(occs)))
				{
					occurs=BooleanClause.Occur.SHOULD;
				}			
				else				
				{
					if(occs!=null)
					{
						throw new ParserException("Invalid value for \"occurs\" attribute of clause:"+occs);
					}
				}
			}
		}
		return occurs;
		
	
public org.apache.lucene.search.QuerygetQuery(org.w3c.dom.Element e)

		BooleanQuery bq=new BooleanQuery();
		bq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
		NodeList nl = e.getElementsByTagName("Clause");
		for(int i=0;i<nl.getLength();i++)
		{
			Element clauseElem=(Element) nl.item(i);
			BooleanClause.Occur occurs=getOccursValue(clauseElem);
			
 			Element clauseQuery=DOMUtils.getFirstChildOrFail(clauseElem);
 			Query q=factory.getQuery(clauseQuery);
 			bq.add(new BooleanClause(q,occurs));			
		}
		
		return bq;