lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mharw...@apache.org
Subject svn commit: r380874 [2/3] - in /lucene/java/trunk/contrib: queries/ queries/src/ queries/src/java/ queries/src/java/org/ queries/src/java/org/apache/ queries/src/java/org/apache/lucene/ queries/src/java/org/apache/lucene/search/ queries/src/java/org/ap...
Date Sat, 25 Feb 2006 00:39:24 GMT
Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/ParserException.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/ParserException.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/ParserException.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/ParserException.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,40 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser;
+
+/**
+ * @author maharwood
+ */
+public class ParserException extends Exception {
+
+	/**
+	 * 
+	 */
+	public ParserException() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+	/**
+	 * @param message
+	 */
+	public ParserException(String message) {
+		super(message);
+		// TODO Auto-generated constructor stub
+	}
+	/**
+	 * @param message
+	 * @param cause
+	 */
+	public ParserException(String message, Throwable cause) {
+		super(message, cause);
+		// TODO Auto-generated constructor stub
+	}
+	/**
+	 * @param cause
+	 */
+	public ParserException(Throwable cause) {
+		super(cause);
+		// TODO Auto-generated constructor stub
+	}
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,15 @@
+package org.apache.lucene.xmlparser;
+
+import org.apache.lucene.search.Query;
+import org.w3c.dom.Element;
+
+/**
+ * Implemented by objects that produce Lucene Query objects from XML streams. Implementations are
+ * expected to be thread-safe so that they can be used to simultaneously parse multiple XML documents.
+ * @author maharwood
+ */
+public interface QueryBuilder {
+	
+	public Query getQuery(Element e) throws ParserException;
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilderFactory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilderFactory.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilderFactory.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/QueryBuilderFactory.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,31 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser;
+
+import java.util.HashMap;
+
+import org.apache.lucene.search.Query;
+import org.w3c.dom.Element;
+
+/**
+ * @author maharwood
+ */
+public class QueryBuilderFactory implements QueryBuilder {
+
+	HashMap builders=new HashMap();
+	
+	public Query getQuery(Element n) throws ParserException {
+		QueryBuilder builder=(QueryBuilder) builders.get(n.getNodeName());
+		if(builder==null)
+		{
+			throw new ParserException("No QueryObjectBuilder defined for node "+n.getNodeName()); 
+		}
+		return builder.getQuery(n); 
+	}
+	public void addBuilder(String nodeName,QueryBuilder builder)
+	{
+		builders.put(nodeName,builder);
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BooleanQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,89 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * @author maharwood 
+ */
+public class BooleanQueryBuilder implements QueryBuilder {
+	
+	private QueryBuilder factory;
+
+	public BooleanQueryBuilder(QueryBuilder factory)
+	{
+		this.factory=factory;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
+	 */
+	public Query getQuery(Element e) throws ParserException {
+		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);
+			
+			//find the first element child which should contain a Query 
+			Element clauseQuery=DOMUtils.getFirstChildElement(clauseElem); 
+			if(clauseQuery!=null)
+			{
+				Query q=factory.getQuery(clauseQuery);
+				bq.add(new BooleanClause(q,occurs));
+				
+			}
+			else
+			{
+				throw new ParserException("BooleanClause missing child query element ");
+			}
+		}
+		
+		return bq;
+	}
+	private BooleanClause.Occur getOccursValue(Element clauseElem) throws ParserException
+	{
+		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;
+		
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,58 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.BoostingQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+
+public class BoostingQueryBuilder implements QueryBuilder
+{
+	
+	private QueryBuilder factory;
+	float defaultBoost=0.01f;
+
+	public BoostingQueryBuilder (QueryBuilder factory)
+	{
+		this.factory=factory;
+	}
+
+	public Query getQuery(Element e) throws ParserException
+	{
+		
+		Element mainQueryElem=DOMUtils.getChildByTagName(e,"Query");
+		if(mainQueryElem==null)
+		{
+			throw new ParserException("BoostingQuery missing a \"Query\" child element");
+		}
+		mainQueryElem=DOMUtils.getFirstChildElement(mainQueryElem);
+		if(mainQueryElem==null)
+		{
+			throw new ParserException("BoostingQuery \"Query\" element missing a child element");
+		}
+		Query mainQuery=factory.getQuery(mainQueryElem);
+		
+
+		Element boostQueryElem=DOMUtils.getChildByTagName(e,"BoostQuery");
+		float boost=DOMUtils.getAttribute(boostQueryElem,"boost",defaultBoost);
+		if(boostQueryElem==null)
+		{
+			throw new ParserException("BoostingQuery missing a \"BoostQuery\" child element");
+		}
+		boostQueryElem=DOMUtils.getFirstChildElement(boostQueryElem);
+		if(boostQueryElem==null)
+		{
+			throw new ParserException("BoostingQuery \"BoostQuery\" element missing a child element");
+		}
+		Query boostQuery=factory.getQuery(boostQueryElem);
+		
+		BoostingQuery bq = new BoostingQuery(mainQuery,boostQuery,boost);
+		bq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return bq;
+
+	}
+
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/ConstantScoreQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/ConstantScoreQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/ConstantScoreQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/ConstantScoreQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,32 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.FilterBuilderFactory;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+public class ConstantScoreQueryBuilder implements QueryBuilder
+{
+	private FilterBuilderFactory filterFactory;
+
+	public ConstantScoreQueryBuilder(FilterBuilderFactory filterFactory)
+	{
+		this.filterFactory=filterFactory;
+	}
+
+	public Query getQuery(Element e) throws ParserException
+	{
+		Element filterElem=DOMUtils.getFirstChildElement(e);
+		if(filterElem==null)
+		{
+			throw new ParserException("ConstantScoreQuery missing child element with filter");
+		}
+		Query q=new ConstantScoreQuery(filterFactory.getFilter(filterElem));
+		q.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return q;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/FuzzyLikeThisQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/FuzzyLikeThisQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/FuzzyLikeThisQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/FuzzyLikeThisQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,47 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.search.FuzzyLikeThisQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+
+public class FuzzyLikeThisQueryBuilder implements QueryBuilder
+{
+	int defaultMaxNumTerms=50;
+	float defaultMinSimilarity=0.5f;
+	int defaultPrefixLength=1;
+	boolean defaultIgnoreTF=false;
+	private Analyzer analyzer;
+	
+	public FuzzyLikeThisQueryBuilder(Analyzer analyzer)
+	{
+		this.analyzer=analyzer;
+	}
+
+	public Query getQuery(Element e) throws ParserException
+	{
+		NodeList nl = e.getElementsByTagName("Field");
+		int maxNumTerms=DOMUtils.getAttribute(e,"maxNumTerms",defaultMaxNumTerms);
+		FuzzyLikeThisQuery fbq=new FuzzyLikeThisQuery(maxNumTerms,analyzer);
+		fbq.setIgnoreTF(DOMUtils.getAttribute(e,"ignoreTF",defaultIgnoreTF));
+		for(int i=0;i<nl.getLength();i++)
+		{
+			Element fieldElem=(Element) nl.item(i);
+			float minSimilarity=DOMUtils.getAttribute(fieldElem,"minSimilarity",defaultMinSimilarity);
+			int prefixLength=DOMUtils.getAttribute(fieldElem,"prefixLength",defaultPrefixLength);
+			String fieldName=DOMUtils.getAttributeWithInheritance(fieldElem,"fieldName");
+			
+			String value=DOMUtils.getText(fieldElem);
+			fbq.addTerms(value,fieldName,minSimilarity,prefixLength);
+		}
+		fbq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+
+		return fbq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/LikeThisQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/LikeThisQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/LikeThisQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/LikeThisQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,58 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.search.similar.MoreLikeThisQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author maharwood
+ */
+public class LikeThisQueryBuilder implements QueryBuilder {
+
+	private Analyzer analyzer;
+	String defaultFieldNames [];
+	int defaultMaxQueryTerms=20;
+	int defaultMinTermFrequency=1;
+	float defaultPercentTermsToMatch=30; //default is a 3rd of selected terms must match
+
+	public LikeThisQueryBuilder(Analyzer analyzer,String [] defaultFieldNames)
+	{
+		this.analyzer=analyzer;
+		this.defaultFieldNames=defaultFieldNames;
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
+	 */
+	public Query getQuery(Element e) throws ParserException {
+		String fieldsList=e.getAttribute("fieldNames"); //a comma-delimited list of fields
+		String fields[]=defaultFieldNames;
+		if((fieldsList!=null)&&(fieldsList.trim().length()>0))
+		{
+			fields=fieldsList.trim().split(",");
+			//trim the fieldnames
+			for (int i = 0; i < fields.length; i++) {
+				fields[i]=fields[i].trim();
+			}
+		}
+		MoreLikeThisQuery mlt=new MoreLikeThisQuery(DOMUtils.getText(e),fields,analyzer);
+		mlt.setMaxQueryTerms(DOMUtils.getAttribute(e,"maxQueryTerms",defaultMaxQueryTerms));
+		mlt.setMinTermFrequency(DOMUtils.getAttribute(e,"minTermFrequency",defaultMinTermFrequency));
+		mlt.setPercentTermsToMatch(DOMUtils.getAttribute(e,"percentTermsToMatch",defaultPercentTermsToMatch)/100);
+
+		mlt.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+
+		return mlt;
+	}
+
+
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/RangeFilterBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,32 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.RangeFilter;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.FilterBuilder;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+
+
+/**
+ * @author maharwood
+ */
+public class RangeFilterBuilder implements FilterBuilder {
+
+
+	public Filter getFilter(Element e) throws ParserException {
+		
+		String fieldName=DOMUtils.getAttributeWithInheritance(e,"fieldName");
+		
+		String lowerTerm=e.getAttribute("lowerTerm");
+		String upperTerm=e.getAttribute("upperTerm");
+		boolean includeLower=DOMUtils.getAttribute(e,"includeLower",true);
+		boolean includeUpper=DOMUtils.getAttribute(e,"includeUpper",true);
+		return new RangeFilter(fieldName,lowerTerm,upperTerm,includeLower,includeUpper);
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanBuilderBase.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanBuilderBase.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanBuilderBase.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanBuilderBase.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,14 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+public abstract class SpanBuilderBase implements SpanQueryBuilder
+{
+	public Query getQuery(Element e) throws ParserException
+	{
+		return getSpanQuery(e);
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanFirstBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanFirstBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanFirstBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanFirstBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,31 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.spans.SpanFirstQuery;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+public class SpanFirstBuilder extends SpanBuilderBase
+{
+    SpanQueryBuilder factory;
+    
+    public SpanFirstBuilder(SpanQueryBuilder factory)
+    {
+        super();
+        this.factory = factory;
+    }
+
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+	    int end=DOMUtils.getAttribute(e,"end",1);
+	    Element child=DOMUtils.getFirstChildElement(e);
+	    SpanQuery q=factory.getSpanQuery(child);
+	    
+		SpanFirstQuery sfq = new SpanFirstQuery(q,end);
+		
+		sfq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return sfq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNearBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNearBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNearBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNearBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,42 @@
+package org.apache.lucene.xmlparser.builders;
+
+import java.util.ArrayList;
+
+import org.apache.lucene.search.spans.SpanNearQuery;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class SpanNearBuilder extends SpanBuilderBase
+{
+	SpanQueryBuilder factory;
+	public SpanNearBuilder(SpanQueryBuilder factory)
+	{
+		this.factory=factory;
+	}
+	
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+		String slopString=e.getAttribute("slop");
+		if((slopString==null)||(slopString.length()==0))
+		{
+			throw new ParserException("SpanTermQuery missing slop property ");			
+		}
+		int slop=Integer.parseInt(slopString);
+		boolean inOrder=DOMUtils.getAttribute(e,"inOrder",false);
+		ArrayList spans=new ArrayList();
+		for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
+		{
+				if (kid.getNodeType() == Node.ELEMENT_NODE) 
+				{
+					spans.add(factory.getSpanQuery((Element) kid));
+				}
+		}
+		SpanQuery[] spanQueries=(SpanQuery[]) spans.toArray(new SpanQuery[spans.size()]);
+		SpanNearQuery snq=new SpanNearQuery(spanQueries,slop,inOrder);
+		return snq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNotBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNotBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNotBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanNotBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,51 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.spans.SpanNotQuery;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+public class SpanNotBuilder extends SpanBuilderBase
+{
+    
+    SpanQueryBuilder factory;    
+
+    /**
+     * @param factory
+     */
+    public SpanNotBuilder(SpanQueryBuilder factory)
+    {
+        super();
+        this.factory = factory;
+    }
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+	    Element includeElem=DOMUtils.getChildByTagName(e,"Include");
+	    if(includeElem!=null)
+		{
+	        includeElem=DOMUtils.getFirstChildElement(includeElem);
+		}
+	    if(includeElem==null)
+	    {
+			throw new ParserException("SpanNotQuery missing Include child Element");	        
+	    }
+	    Element excludeElem=DOMUtils.getChildByTagName(e,"Exclude");
+	    if(excludeElem!=null)
+		{
+	        excludeElem=DOMUtils.getFirstChildElement(excludeElem);
+		}
+	    if(excludeElem==null)
+	    {
+			throw new ParserException("SpanNotQuery missing Exclude child Element");	        
+	    }
+	    SpanQuery include=factory.getSpanQuery(includeElem);
+	    SpanQuery exclude=factory.getSpanQuery(excludeElem);
+	    
+		SpanNotQuery snq = new SpanNotQuery(include,exclude);
+		
+		snq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return snq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,40 @@
+package org.apache.lucene.xmlparser.builders;
+
+import java.util.ArrayList;
+
+import org.apache.lucene.search.spans.SpanOrQuery;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class SpanOrBuilder extends SpanBuilderBase
+{
+    
+    SpanQueryBuilder factory;
+    
+    public SpanOrBuilder(SpanQueryBuilder factory)
+    {
+        super();
+        this.factory = factory;
+    }
+    
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+	    ArrayList clausesList=new ArrayList();
+		for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
+		{
+			if (kid.getNodeType() == Node.ELEMENT_NODE) 
+			{
+				SpanQuery clause=factory.getSpanQuery((Element) kid);
+				clausesList.add(clause);				
+			}
+		}	    
+		SpanQuery[] clauses=(SpanQuery[]) clausesList.toArray(new SpanQuery[clausesList.size()]);
+		SpanOrQuery soq = new SpanOrQuery(clauses);		
+		soq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return soq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrTermsBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrTermsBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrTermsBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanOrTermsBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,62 @@
+package org.apache.lucene.xmlparser.builders;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.spans.SpanOrQuery;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.SpanTermQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+public class SpanOrTermsBuilder extends SpanBuilderBase
+{
+    Analyzer analyzer;
+    
+    
+    /**
+     * @param analyzer
+     */
+    public SpanOrTermsBuilder(Analyzer analyzer)
+    {
+        super();
+        this.analyzer = analyzer;
+    }
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+		String fieldName=DOMUtils.getAttributeWithInheritance(e,"fieldName");
+		if(fieldName==null)
+		{
+			throw new ParserException("Error: SpanOrTermsBuilder missing \"fieldName\" property");
+		}
+
+		String value=DOMUtils.getText(e);
+		
+		try
+		{
+			ArrayList clausesList=new ArrayList();
+			TokenStream ts=analyzer.tokenStream(fieldName,new StringReader(value));
+			Token token=ts.next();
+			while(token!=null)
+			{
+			    SpanTermQuery stq=new SpanTermQuery(new Term(fieldName,token.termText()));
+			    clausesList.add(stq);
+				token=ts.next();		    
+			}
+			SpanOrQuery soq=new SpanOrQuery((SpanQuery[]) clausesList.toArray(new SpanQuery[clausesList.size()]));
+			soq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+			return soq;
+		}
+		catch(IOException ioe)
+		{
+		    throw new ParserException("IOException parsing value:"+value);
+		}
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,18 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+/**
+ * @author maharwood
+ */
+public interface SpanQueryBuilder extends QueryBuilder{
+	
+	public SpanQuery getSpanQuery(Element e) throws ParserException;
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilderFactory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilderFactory.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilderFactory.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanQueryBuilderFactory.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,34 @@
+package org.apache.lucene.xmlparser.builders;
+
+import java.util.HashMap;
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+/**
+ * @author maharwood
+ */
+public class SpanQueryBuilderFactory implements SpanQueryBuilder {
+
+	HashMap builders=new HashMap();
+	
+	public Query getQuery(Element e) throws ParserException {
+		return getSpanQuery(e);
+	}
+	public void addBuilder(String nodeName,SpanQueryBuilder builder)
+	{
+		builders.put(nodeName,builder);
+	}
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+		SpanQueryBuilder builder=(SpanQueryBuilder) builders.get(e.getNodeName());
+		if(builder==null)
+		{
+			throw new ParserException("No SpanQueryObjectBuilder defined for node "+e.getNodeName()); 
+		}
+		return builder.getSpanQuery(e); 
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanTermBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanTermBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanTermBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/SpanTermBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,31 @@
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.SpanTermQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+public class SpanTermBuilder extends SpanBuilderBase
+{
+
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+		String fieldName=DOMUtils.getAttributeWithInheritance(e,"fieldName");
+		String value=DOMUtils.getText(e);
+		if((fieldName==null)||(fieldName.length()==0))
+		{
+			throw new ParserException("SpanTermQuery missing fieldName property ");
+		}
+		if((value==null)||(value.length()==0))
+		{
+			throw new ParserException("TermQuery missing value property ");
+		}
+		SpanTermQuery stq = new SpanTermQuery(new Term(fieldName,value));
+		
+		stq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return stq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,37 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author maharwood
+ */
+public class TermQueryBuilder implements QueryBuilder {
+
+	public Query getQuery(Element e) throws ParserException {
+		String field=DOMUtils.getAttributeWithInheritance(e,"fieldName");
+		String value=DOMUtils.getText(e);
+		if((field==null)||(field.length()==0))
+		{
+			throw new ParserException("TermQuery element missing fieldName attribute");
+		}
+		if((value==null)||(value.length()==0))
+		{
+			throw new ParserException("TermQuery element missing child text property ");
+		}
+		TermQuery tq = new TermQuery(new Term(field,value));
+		
+		tq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return tq;
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsFilterBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsFilterBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsFilterBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsFilterBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,79 @@
+package org.apache.lucene.xmlparser.builders;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.TermsFilter;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.FilterBuilder;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * @author maharwood
+ *
+ * @
+ */
+public class TermsFilterBuilder implements FilterBuilder
+{
+	Analyzer analyzer;
+	
+	/**
+	 * @param analyzer
+	 */
+	public TermsFilterBuilder(Analyzer analyzer)
+	{
+		this.analyzer = analyzer;
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
+	 */
+	public Filter getFilter(Element e) throws ParserException
+	{
+		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;
+	}
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,44 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+
+
+/**
+ * @author maharwood
+ */
+public class UserInputQueryBuilder implements QueryBuilder {
+
+	QueryParser parser;
+	
+	/**
+	 * @param parser
+	 */
+	public UserInputQueryBuilder(QueryParser parser) {
+		this.parser = parser;
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
+	 */
+	public Query getQuery(Element e) throws ParserException {
+		String text=DOMUtils.getText(e);
+		try {
+			Query q = parser.parse(text);
+			q.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+			return q;
+		} catch (ParseException e1) {
+			throw new ParserException(e1.getMessage());
+		}
+	}
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BooleanQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BooleanQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BooleanQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BooleanQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<BooleanQuery fieldName="contents">
+	<Clause occurs="should">
+		<TermQuery>merger</TermQuery>
+	</Clause>
+	<Clause occurs="mustnot">
+		<TermQuery>sumitomo</TermQuery>
+	</Clause>
+	<Clause occurs="must">
+		<TermQuery>bank</TermQuery>
+	</Clause>
+</BooleanQuery>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<BoostingQuery>
+	<!-- Find docs about banks, preferably merger info and preferably not "World bank" -->
+	<Query>
+		<BooleanQuery fieldName="contents">
+			<Clause occurs="should">
+				<TermQuery>merger</TermQuery>
+			</Clause>
+			<Clause occurs="must">
+				<TermQuery>bank</TermQuery>
+			</Clause>
+		</BooleanQuery>	
+	</Query>
+	<BoostQuery boost="0.01">
+			<UserQuery>"world bank"</UserQuery>
+	</BoostQuery>
+</BoostingQuery>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/ConstantScoreQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/ConstantScoreQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/ConstantScoreQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/ConstantScoreQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ConstantScoreQuery>
+	<RangeFilter fieldName="date" lowerTerm="19870409" upperTerm="19870412"/>
+</ConstantScoreQuery>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/FuzzyLikeThisQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/FuzzyLikeThisQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/FuzzyLikeThisQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/FuzzyLikeThisQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FuzzyLikeThisQuery>
+	<!-- Matches on misspelt "Sumitomo" bank -->
+	<Field fieldName="contents">
+		Sumitimo bank 
+	</Field>
+</FuzzyLikeThisQuery>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/LikeThisQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/LikeThisQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/LikeThisQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/LikeThisQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LikeThisQuery percentTermsToMatch="5">
+IRAQI TROOPS REPORTED PUSHING BACK IRANIANS Iraq said today its troops were pushing Iranian forces out of 
+	positions they had initially occupied when they launched a new offensive near the southern port of 
+	Basra early yesterday.     A High Command communique said Iraqi troops had won a significant victory 
+	and were continuing to advance.     Iraq said it had foiled a three-pronged thrust some 10 km 
+	(six miles) from Basra, but admitted the Iranians had occupied ground held by the Mohammed al-Qassem 
+	unit, one of three divisions attacked.     The communique said Iranian Revolutionary Guards were under 
+	assault from warplanes, helicopter gunships, heavy artillery and tanks.     "Our forces are continuing 
+	their advance until they purge the last foothold" occupied by the Iranians, it said.     
+	(Iran said its troops had killed or wounded more than 4,000 Iraqis and were stabilising their new positions.)     
+	The Baghdad communique said Iraqi planes also destroyed oil installations at Iran's southwestern Ahvaz field 
+	during a raid today. It denied an Iranian report that an Iraqi jet was shot down.     
+	Iraq also reported a naval battle at the northern tip of the Gulf. Iraqi naval units and forces defending an 
+	offshore terminal sank six Iranian out of 28 Iranian boats attempting to attack an offshore terminal, 
+	the communique said.      Reuter 3;
+</LikeThisQuery>
\ No newline at end of file

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/RangeFilterQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/RangeFilterQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/RangeFilterQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/RangeFilterQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FilteredQuery>
+	<Query>
+		<BooleanQuery fieldName="contents">
+			<Clause occurs="should">
+				<TermQuery>merger</TermQuery>
+			</Clause>
+			<Clause occurs="mustnot">
+				<TermQuery >sumitomo</TermQuery>		
+			</Clause>
+			<Clause occurs="must">
+				<TermQuery>bank</TermQuery>
+			</Clause>
+		</BooleanQuery>
+	</Query>
+	
+	<Filter>
+		<RangeFilter fieldName="date" lowerTerm="19870409" upperTerm="19870412"/>
+	</Filter>
+	
+</FilteredQuery>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SpanOr fieldName="contents">
+	<SpanNear slop="8" inOrder="false" >		
+			<SpanOr>
+				<SpanTerm>killed</SpanTerm>
+				<SpanTerm>died</SpanTerm>
+				<SpanTerm>dead</SpanTerm>
+			</SpanOr>
+			<SpanOr>
+				<!-- a less verbose way of declaring SpanTerm declarations - these are analyzed
+					into a series of Tokens which are added as SpanTerm elements of a SpanOr
+				-->
+				<SpanOrTerms>miner miners</SpanOrTerms>
+				<!-- finds mine near worker or workers -->
+				<SpanNear slop="6" inOrder="false">		
+					<SpanTerm>mine</SpanTerm>					
+					<SpanOrTerms>worker workers</SpanOrTerms>
+				</SpanNear>
+			</SpanOr>
+	</SpanNear>	
+	<SpanFirst end="10">
+		<SpanOrTerms>fire burn</SpanOrTerms>
+	</SpanFirst> 
+	<!-- Other Span examples....
+		
+	<SpanNot>
+		<Include>
+				<SpanNear slop="2" inOrder="2">		
+						<SpanTerm>social</SpanTerm>
+						<SpanTerm>services</SpanTerm>
+				</SpanNear>				
+		</Include>
+		<Exclude>
+				<SpanTerm>public</SpanTerm>
+		</Exclude>
+	</SpanNot>
+		-->
+</SpanOr>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TermQuery fieldName="contents">sumitomo</TermQuery>
\ No newline at end of file

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermsFilterQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermsFilterQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermsFilterQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TermsFilterQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FilteredQuery>
+	<Query>
+		<BooleanQuery fieldName="contents">
+			<Clause occurs="should">
+				<TermQuery>merger</TermQuery>
+			</Clause>
+			<Clause occurs="must">
+				<TermQuery>bank</TermQuery> 
+			</Clause>
+		</BooleanQuery>	
+	</Query>
+	<Filter>
+		<!-- TermsFilter uses an analyzer to tokenize Field text and creates a filter for docs which 
+			have ANY of the supplied terms. Unlike a RangeFilter this can be used for filtering on 
+			multiple terms that are not necessarily in a sequence. An example might be a list of primary
+			keys from a database query result or perhaps a choice of "category" labels picked by the end 
+			user.
+			As a filter, this is much faster than the equivalent query (a BooleanQuery with many 
+			"should" TermQueries)
+			
+			This example might be just a list of Saturdays ie not a contiguous range of values
+			which can be handled by rangefilter
+		-->
+		<TermsFilter>			
+			<Field fieldName="date" >19870601 19870608 19870615</Field>
+		</TermsFilter> 
+	</Filter>
+	
+</FilteredQuery>

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java Fri Feb 24 16:39:18 2006
@@ -0,0 +1,166 @@
+/*
+ * Created on 25-Jan-2006
+ */
+package org.apache.lucene.xmlparser;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+
+/**
+ * @author maharwood
+ */
+public class TestParser extends TestCase {
+
+	CoreParser builder;
+	static Directory dir;
+	Analyzer analyzer=new StandardAnalyzer();
+	IndexReader reader;
+	private IndexSearcher searcher;
+	
+	//CHANGE THIS TO SEE OUTPUT
+	boolean printResults=false;
+	
+	
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		
+		//initialize the parser
+		builder=new CorePlusExtensionsParser(analyzer,new QueryParser("contents", analyzer));
+		
+		//initialize the index (done once, then cached in static data for use with ALL tests)		
+		if(dir==null)
+		{
+			BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt"))); 
+			dir=new RAMDirectory();
+			IndexWriter writer=new IndexWriter(dir,analyzer,true);
+			String line = d.readLine();		
+			while(line!=null)
+			{
+				int endOfDate=line.indexOf('\t');
+				String date=line.substring(0,endOfDate).trim();
+				String content=line.substring(endOfDate).trim();
+				org.apache.lucene.document.Document doc =new org.apache.lucene.document.Document();
+				doc.add(new Field("date",date,Field.Store.YES,Field.Index.TOKENIZED));
+				doc.add(new Field("contents",content,Field.Store.YES,Field.Index.TOKENIZED));
+				writer.addDocument(doc);
+				line=d.readLine();
+			}			
+			d.close();
+		}
+		reader=IndexReader.open(dir);
+		searcher=new IndexSearcher(reader);
+		
+	}
+	
+	
+	
+	
+	protected void tearDown() throws Exception {
+		reader.close();
+		searcher.close();
+//		dir.close();
+		
+	}
+	public void testSimpleXML() throws ParserException, IOException
+	{
+			Query q=parse("TermQuery.xml");
+			dumpResults("TermQuery", q, 5);
+	}
+	public void testBooleanQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("BooleanQuery.xml");
+			dumpResults("BooleanQuery", q, 5);
+	}
+	public void testRangeFilterQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("RangeFilterQuery.xml");
+			dumpResults("RangeFilter", q, 5);
+	}
+	public void testUserQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("UserInputQuery.xml");
+			dumpResults("UserInput with Filter", q, 5);
+	}
+	public void testLikeThisQueryXML() throws Exception
+	{
+			Query q=parse("LikeThisQuery.xml");
+			dumpResults("like this", q, 5);
+	}
+	public void testBoostingQueryXML() throws Exception
+	{
+			Query q=parse("BoostingQuery.xml");
+			dumpResults("boosting ",q, 5);
+	}
+	public void testFuzzyLikeThisQueryXML() throws Exception
+	{
+			Query q=parse("FuzzyLikeThisQuery.xml");
+			//show rewritten fuzzyLikeThisQuery - see what is being matched on
+			if(printResults)
+			{
+				System.out.println(q.rewrite(reader));
+			}
+			dumpResults("FuzzyLikeThis", q, 5);
+	}
+	public void testTermsFilterXML() throws Exception
+	{
+			Query q=parse("TermsFilterQuery.xml");
+			dumpResults("Terms Filter",q, 5);
+	}
+	public void testSpanTermXML() throws Exception
+	{
+			Query q=parse("SpanQuery.xml");
+			dumpResults("Span Query",q, 5);
+	}
+	public void testConstantScoreQueryXML() throws Exception
+	{
+			Query q=parse("ConstantScoreQuery.xml");
+			dumpResults("ConstantScoreQuery",q, 5);
+	}
+	
+
+
+	//================= Helper methods ===================================
+	private Query parse(String xmlFileName) throws ParserException, IOException
+	{
+		InputStream xmlStream=TestParser.class.getResourceAsStream(xmlFileName);
+		Query result=builder.parse(xmlStream);
+		xmlStream.close();
+		return result;
+	}
+	private void dumpResults(String qType,Query q, int numDocs) throws IOException
+	{
+		Hits h = searcher.search(q);
+		assertTrue(qType +" should produce results ", h.length()>0);
+		if(printResults)
+		{
+			System.out.println("========="+qType+"============");
+			for(int i=0;i<Math.min(numDocs,h.length());i++)
+			{
+				org.apache.lucene.document.Document ldoc=h.doc(i);
+				System.out.println("["+ldoc.get("date")+"]"+ldoc.get("contents"));
+			}
+			System.out.println();
+		}
+	}
+	
+
+}

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQuery.xml
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQuery.xml?rev=380874&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQuery.xml Fri Feb 24 16:39:18 2006
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FilteredQuery>
+	<Query>
+		<UserQuery>"Bank of England"</UserQuery>
+	</Query>
+	<Filter>
+		<RangeFilter fieldName="date" lowerTerm="19870409" upperTerm="19870412"/>
+	</Filter>
+	
+</FilteredQuery>



Mime
View raw message