You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by ka...@apache.org on 2009/02/09 12:49:34 UTC

svn commit: r742411 - in /lucene/java/trunk/contrib: ./ xml-query-parser/ xml-query-parser/src/java/org/apache/lucene/xmlparser/ xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/ xml-query-parser/src/test/org/apache/lucene/xmlparser/

Author: kalle
Date: Mon Feb  9 11:49:33 2009
New Revision: 742411

URL: http://svn.apache.org/viewvc?rev=742411&view=rev
Log:
LUCENE-1531
Added support for BoostingTermQuery to XML query parser.

Added:
    lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java
    lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingTermQuery.xml
Modified:
    lucene/java/trunk/contrib/CHANGES.txt
    lucene/java/trunk/contrib/xml-query-parser/LuceneCoreQuery.dtd
    lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/CoreParser.java
    lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml
    lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java

Modified: lucene/java/trunk/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/CHANGES.txt?rev=742411&r1=742410&r2=742411&view=diff
==============================================================================
--- lucene/java/trunk/contrib/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/CHANGES.txt Mon Feb  9 11:49:33 2009
@@ -31,6 +31,9 @@
     RangeQuery at the expense of added space (additional indexed
     tokens) consumed in the index.  (Uwe Schindler via Mike McCandless)
 
+ 2. LUCENE-1531: Added support for BoostingTermQuery to XML query parser. (Karl Wettin)
+
+
 Documentation
 
  (None)

Modified: lucene/java/trunk/contrib/xml-query-parser/LuceneCoreQuery.dtd
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/LuceneCoreQuery.dtd?rev=742411&r1=742410&r2=742411&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/LuceneCoreQuery.dtd (original)
+++ lucene/java/trunk/contrib/xml-query-parser/LuceneCoreQuery.dtd Mon Feb  9 11:49:33 2009
@@ -53,8 +53,8 @@
 -->
 
 <!-- @hidden Define core types of XML elements -->
-<!ENTITY % coreSpanQueries "SpanOr|SpanNear|SpanOrTerms|SpanFirst|SpanNot|SpanTerm" >
-<!ENTITY % coreQueries "BooleanQuery|UserQuery|FilteredQuery|TermQuery|TermsQuery|MatchAllDocsQuery|ConstantScoreQuery" >
+<!ENTITY % coreSpanQueries "SpanOr|SpanNear|SpanOrTerms|SpanFirst|SpanNot|SpanTerm|BoostingTermQuery" >
+<!ENTITY % coreQueries "BooleanQuery|UserQuery|FilteredQuery|TermQuery|TermsQuery|MatchAllDocsQuery|ConstantScoreQuery|BoostingTermQuery" >
 <!ENTITY % coreFilters "RangeFilter|CachedFilter" >
 
 <!-- @hidden Allow for extensions -->
@@ -186,6 +186,29 @@
 <!ATTLIST TermQuery fieldName CDATA #IMPLIED>
 
 
+<!--
+  A boosted term query - no analysis is done of the child text. Also a span member.
+
+  (Text below is copied from the javadocs of BoostingTermQuery)
+   
+  The BoostingTermQuery is very similar to the {@link org.apache.lucene.search.spans.SpanTermQuery} except
+  that it factors in the value of the payload located at each of the positions where the
+  {@link org.apache.lucene.index.Term} occurs.
+
+  In order to take advantage of this, you must override {@link org.apache.lucene.search.Similarity#scorePayload(String, byte[],int,int)}
+  which returns 1 by default.
+
+  Payload scores are averaged across term occurrences in the document.
+
+  @see org.apache.lucene.search.Similarity#scorePayload(String, byte[], int, int)
+-->
+<!ELEMENT BoostingTermQuery (#PCDATA)>
+<!-- Optional boost for matches on this query. Values > 1 -->
+<!ATTLIST TermQuery boost CDATA "1.0">
+<!-- fieldName must be defined here or is taken from the most immediate parent XML element that defines a "fieldName" attribute -->
+<!ATTLIST TermQuery fieldName CDATA #IMPLIED>
+
+
 
 <!-- 
 	The equivalent of a BooleanQuery with multiple optional TermQuery clauses.

Modified: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/CoreParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/CoreParser.java?rev=742411&r1=742410&r2=742411&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/CoreParser.java (original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/CoreParser.java Mon Feb  9 11:49:33 2009
@@ -8,22 +8,7 @@
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.xmlparser.builders.BooleanQueryBuilder;
-import org.apache.lucene.xmlparser.builders.ConstantScoreQueryBuilder;
-import org.apache.lucene.xmlparser.builders.FilteredQueryBuilder;
-import org.apache.lucene.xmlparser.builders.MatchAllDocsQueryBuilder;
-import org.apache.lucene.xmlparser.builders.CachedFilterBuilder;
-import org.apache.lucene.xmlparser.builders.RangeFilterBuilder;
-import org.apache.lucene.xmlparser.builders.SpanFirstBuilder;
-import org.apache.lucene.xmlparser.builders.SpanNearBuilder;
-import org.apache.lucene.xmlparser.builders.SpanNotBuilder;
-import org.apache.lucene.xmlparser.builders.SpanOrBuilder;
-import org.apache.lucene.xmlparser.builders.SpanOrTermsBuilder;
-import org.apache.lucene.xmlparser.builders.SpanQueryBuilderFactory;
-import org.apache.lucene.xmlparser.builders.SpanTermBuilder;
-import org.apache.lucene.xmlparser.builders.TermQueryBuilder;
-import org.apache.lucene.xmlparser.builders.TermsQueryBuilder;
-import org.apache.lucene.xmlparser.builders.UserInputQueryBuilder;
+import org.apache.lucene.xmlparser.builders.*;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -113,7 +98,11 @@
 		sqof.addBuilder("SpanNear",snb);
 		queryFactory.addBuilder("SpanNear",snb);
 
-		SpanTermBuilder snt=new SpanTermBuilder();
+    BoostingTermBuilder btb=new BoostingTermBuilder();
+    sqof.addBuilder("BoostingTermQuery",btb);
+    queryFactory.addBuilder("BoostingTermQuery",btb);        
+
+    SpanTermBuilder snt=new SpanTermBuilder();
 		sqof.addBuilder("SpanTerm",snt);
 		queryFactory.addBuilder("SpanTerm",snt);
 		

Added: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java?rev=742411&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/BoostingTermBuilder.java Mon Feb  9 11:49:33 2009
@@ -0,0 +1,41 @@
+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.search.payloads.BoostingTermQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.w3c.dom.Element;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class BoostingTermBuilder extends SpanBuilderBase
+{
+
+	public SpanQuery getSpanQuery(Element e) throws ParserException
+	{
+ 		String fieldName=DOMUtils.getAttributeWithInheritanceOrFail(e,"fieldName");
+ 		String value=DOMUtils.getNonBlankTextOrFail(e);
+  		BoostingTermQuery btq = new BoostingTermQuery(new Term(fieldName,value));
+
+  		btq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+		return btq;
+
+	}
+
+}
\ No newline at end of file

Added: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingTermQuery.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingTermQuery.xml?rev=742411&view=auto
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingTermQuery.xml (added)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/BoostingTermQuery.xml Mon Feb  9 11:49:33 2009
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<BoostingTermQuery fieldName="contents">sumitomo</BoostingTermQuery>

Modified: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml?rev=742411&r1=742410&r2=742411&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml (original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/SpanQuery.xml Mon Feb  9 11:49:33 2009
@@ -15,7 +15,8 @@
 				<SpanNear slop="6" inOrder="false">		
 					<SpanTerm>mine</SpanTerm>					
 					<SpanOrTerms>worker workers</SpanOrTerms>
-				</SpanNear>
+          <BoostingTermQuery>heavy</BoostingTermQuery>
+        </SpanNear>
 			</SpanOr>
 	</SpanNear>	
 	<SpanFirst end="10">

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?rev=742411&r1=742410&r2=742411&view=diff
==============================================================================
--- 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 Mon Feb  9 11:49:33 2009
@@ -1,9 +1,6 @@
 package org.apache.lucene.xmlparser;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
 
 import junit.framework.TestCase;
 
@@ -74,7 +71,7 @@
 				line=d.readLine();
 			}			
 			d.close();
-                        writer.close();
+      writer.close();
 		}
 		reader=IndexReader.open(dir);
 		searcher=new IndexSearcher(reader);
@@ -148,7 +145,12 @@
 			Query q=parse("TermsFilterQuery.xml");
 			dumpResults("Terms Filter",q, 5);
 	}
-	public void testSpanTermXML() throws Exception
+  public void testBoostingTermQueryXML() throws Exception
+	{
+			Query q=parse("BoostingTermQuery.xml");
+			dumpResults("BoostingTermQuery",q, 5);
+	}
+  public void testSpanTermXML() throws Exception
 	{
 			Query q=parse("SpanQuery.xml");
 			dumpResults("Span Query",q, 5);