lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mharw...@apache.org
Subject svn commit: r441667 - in /lucene/java/trunk/contrib/xml-query-parser/src: java/org/apache/lucene/xmlparser/builders/ test/org/apache/lucene/xmlparser/
Date Fri, 08 Sep 2006 21:45:15 GMT
Author: mharwood
Date: Fri Sep  8 14:45:14 2006
New Revision: 441667

URL: http://svn.apache.org/viewvc?view=rev&rev=441667
Log:
Fixed bug where BooleanQueryBuilder.java and BooleanFilterBuilder.java were mistakenly adding
all child (and grandchild) clauses to the top node. A call to Element.getElementsByTagName
was the offending code - this descends full depth rather than getting only immediate children
which is the desired behaviour. Thanks to Jingkei Ly for spotting this bug.

Added:
    lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/NestedBooleanQuery.xml
Modified:
    lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanFilterBuilder.java
    lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java
    lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java

Modified: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanFilterBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanFilterBuilder.java?view=diff&rev=441667&r1=441666&r2=441667
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanFilterBuilder.java
(original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanFilterBuilder.java
Fri Sep  8 14:45:14 2006
@@ -11,6 +11,7 @@
 import org.apache.lucene.xmlparser.FilterBuilder;
 import org.apache.lucene.xmlparser.ParserException;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 
@@ -28,15 +29,20 @@
 
 	public Filter getFilter(Element e) throws ParserException {
 		BooleanFilter bf=new BooleanFilter();
-		NodeList nl = e.getElementsByTagName("Clause");
+		NodeList nl = e.getChildNodes();
+		
 		for(int i=0;i<nl.getLength();i++)
 		{
-			Element clauseElem=(Element) nl.item(i);
-			BooleanClause.Occur occurs=BooleanQueryBuilder.getOccursValue(clauseElem);
+			Node node = nl.item(i);
+			if(node.getNodeName().equals("Clause"))
+			{
+				Element clauseElem=(Element) node;
+				BooleanClause.Occur occurs=BooleanQueryBuilder.getOccursValue(clauseElem);
 			
- 			Element clauseFilter=DOMUtils.getFirstChildOrFail(clauseElem);
- 			Filter f=factory.getFilter(clauseFilter);
- 			bf.add(new FilterClause(f,occurs));			
+	 			Element clauseFilter=DOMUtils.getFirstChildOrFail(clauseElem);
+	 			Filter f=factory.getFilter(clauseFilter);
+	 			bf.add(new FilterClause(f,occurs));
+			}
 		}
 		
 		return bf;

Modified: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java?view=diff&rev=441667&r1=441666&r2=441667
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java
(original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java
Fri Sep  8 14:45:14 2006
@@ -10,6 +10,7 @@
 import org.apache.lucene.xmlparser.ParserException;
 import org.apache.lucene.xmlparser.QueryBuilder;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 
@@ -32,15 +33,20 @@
 		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.getElementsByTagName("Clause");
+		
+		NodeList nl = e.getChildNodes();
 		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));			
+			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;

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/NestedBooleanQuery.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/NestedBooleanQuery.xml?view=auto&rev=441667
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/NestedBooleanQuery.xml
(added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/NestedBooleanQuery.xml
Fri Sep  8 14:45:14 2006
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	This query was added to demonstrate nested boolean queries - there
+	was a bug in the XML parser which added ALL child <Clause> tags to 
+	the top level tags ie. took child and grandchild elements instead
+	of just child elements. This was due to the use of the 
+	Element.getElementsByTagName() call in BooleanQueryBuilder
+-->	
+<BooleanQuery fieldName="contents">	
+	<Clause occurs="should">
+		<BooleanQuery fieldName="contents">
+			<Clause occurs="must">
+				<TermQuery>doesNotExistButShouldBeOKBecauseOtherClauseExists</TermQuery>
+			</Clause>
+		</BooleanQuery>
+	</Clause>
+	<Clause occurs="should">
+		<TermQuery>bank</TermQuery>
+	</Clause>
+</BooleanQuery>

Modified: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java?view=diff&rev=441667&r1=441666&r2=441667
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
(original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
Fri Sep  8 14:45:14 2006
@@ -150,6 +150,11 @@
 			Query q=parse("BooleanFilter.xml");
 			dumpResults("Boolean filter", q, 5);
 	}
+	public void testNestedBooleanQuery() throws ParserException, IOException
+	{
+			Query q=parse("NestedBooleanQuery.xml");
+			dumpResults("Nested Boolean query", q, 5);
+	}
 	
 
 



Mime
View raw message