FileDocCategorySizeDatePackage
BooleanQueryBuilder.javaAPI DocApache Lucene 2.1.03074Wed Feb 14 10:46:20 GMT 2007org.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(DOMUtils.getAttribute(e,"disableCoord",false));
		bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e,"minimumNumberShouldMatch",0));
		bq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
		
		NodeList nl = e.getChildNodes();
		for(int i=0;i<nl.getLength();i++)
		{
			Node node = nl.item(i);
			if(node.getNodeName().equals("Clause"))
			{
				Element clauseElem=(Element) node;
				BooleanClause.Occur occurs=getOccursValue(clauseElem);
				
	 			Element clauseQuery=DOMUtils.getFirstChildOrFail(clauseElem);
	 			Query q=factory.getQuery(clauseQuery);
	 			bq.add(new BooleanClause(q,occurs));
			}
		}
		
		return bq;