Apache Lucene open-source search software
LUCENE-3347: XML query parser did not always incorporate boosts from UserQuery elements
Uwe Schindler347308b845f4
diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txtindex 313ea2782d0..c56159af27d 100644--- a/lucene/contrib/CHANGES.txt+++ b/lucene/contrib/CHANGES.txt@@ -102,6 +102,9 @@ Bug Fixesyour string and encode/decode it using the default charset, it now usesa StringReader. Finally, MoreLikeThis's methods that take File, URL, InputStream,are deprecated, please create the Reader yourself. (Trejkaz, Robert Muir)++ * LUCENE-3347: XML query parser did not always incorporate boosts from+ UserQuery elements. (Moogie, Uwe Schindler)======================= Lucene 3.3.0 =======================diff --git a/lucene/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java b/lucene/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.javaindex 0ada2ca00a8..d25f274dc3c 100644--- a/lucene/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java+++ b/lucene/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java@@ -74,7 +74,8 @@ public class UserInputQueryBuilder implements QueryBuilder {QueryParser parser=createQueryParser(fieldName, analyzer);q = parser.parse(text);}- q.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));+ // use the boost of the original query here, too and multiply (which may be != 1.0f):+ q.setBoost(q.getBoost()*DOMUtils.getAttribute(e,"boost",1.0f));return q;} catch (ParseException e1) {throw new ParserException(e1.getMessage());diff --git a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.javaindex ffe82630b65..4e66c4da6d5 100644--- a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java+++ b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java@@ -121,6 +121,7 @@ public class TestParser extends LuceneTestCase {public void testCustomFieldUserQueryXML() throws ParserException, IOException{Query q=parse("UserInputQueryCustomField.xml");+ assertEquals(20.0f, q.getBoost());int h = searcher.search(q, null, 1000).totalHits;assertEquals("UserInputQueryCustomField should produce 0 result ", 0,h);}diff --git a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQueryCustomField.xml b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQueryCustomField.xmlindex 1f22fac90be..86b2c01fe96 100644--- a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQueryCustomField.xml+++ b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/UserInputQueryCustomField.xml@@ -1,2 +1,2 @@<?xml version="1.0" encoding="UTF-8"?>-<UserQuery fieldName="doesNotExist">Bank</UserQuery>+<UserQuery fieldName="doesNotExist" boost="10">Bank^2</UserQuery>