Apache Solr open-source search software
LUCENE-7219: Make queryparser/xml (Point|LegacyNumeric)RangeQuery builders match the underlying queries' (lower|upper)Term optionality logic. (Kaneshanathan Srivisagan, Christine Poerschke)
Christine Poerschkec57db0258058
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex d7e1b3902bf..d00972b4d0e 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -84,6 +84,10 @@ Bug Fixesthat led to IllegalStateException being thrown when nothing was wrong.(David Smiley, yonik)+* LUCENE-7219: Make queryparser/xml (Point|LegacyNumeric)RangeQuery builders+ match the underlying queries' (lower|upper)Term optionality logic.+ (Kaneshanathan Srivisagan, Christine Poerschke)+Documentation* LUCENE-7223: Improve XXXPoint javadocs to make it clear that youdiff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LegacyNumericRangeQueryBuilder.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LegacyNumericRangeQueryBuilder.javaindex e19596430e2..f7aef3f477b 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LegacyNumericRangeQueryBuilder.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/LegacyNumericRangeQueryBuilder.java@@ -45,14 +45,14 @@ import org.w3c.dom.Element;* <tr>* <td>lowerTerm</td>* <td>Specified by <tt>type</tt></td>- * <td>Yes</td>- * <td>N/A</td>+ * <td>No</td>+ * <td>Null</td>* </tr>* <tr>* <td>upperTerm</td>* <td>Specified by <tt>type</tt></td>- * <td>Yes</td>- * <td>N/A</td>+ * <td>No</td>+ * <td>Null</td>* </tr>* <tr>* <td>type</td>@@ -91,8 +91,8 @@ public class LegacyNumericRangeQueryBuilder implements QueryBuilder {@Overridepublic Query getQuery(Element e) throws ParserException {String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");- String lowerTerm = DOMUtils.getAttributeOrFail(e, "lowerTerm");- String upperTerm = DOMUtils.getAttributeOrFail(e, "upperTerm");+ final String lowerTerm = DOMUtils.getAttribute(e, "lowerTerm", null);+ final String upperTerm = DOMUtils.getAttribute(e, "upperTerm", null);boolean lowerInclusive = DOMUtils.getAttribute(e, "includeLower", true);boolean upperInclusive = DOMUtils.getAttribute(e, "includeUpper", true);int precisionStep = DOMUtils.getAttribute(e, "precisionStep", LegacyNumericUtils.PRECISION_STEP_DEFAULT);@@ -101,20 +101,28 @@ public class LegacyNumericRangeQueryBuilder implements QueryBuilder {try {Query filter;if (type.equalsIgnoreCase("int")) {- filter = LegacyNumericRangeQuery.newIntRange(field, precisionStep, Integer- .valueOf(lowerTerm), Integer.valueOf(upperTerm), lowerInclusive,+ filter = LegacyNumericRangeQuery.newIntRange(field, precisionStep,+ (lowerTerm == null ? null : Integer.valueOf(lowerTerm)),+ (upperTerm == null ? null : Integer.valueOf(upperTerm)),+ lowerInclusive,upperInclusive);} else if (type.equalsIgnoreCase("long")) {- filter = LegacyNumericRangeQuery.newLongRange(field, precisionStep, Long- .valueOf(lowerTerm), Long.valueOf(upperTerm), lowerInclusive,+ filter = LegacyNumericRangeQuery.newLongRange(field, precisionStep,+ (lowerTerm == null ? null : Long.valueOf(lowerTerm)),+ (upperTerm == null ? null : Long.valueOf(upperTerm)),+ lowerInclusive,upperInclusive);} else if (type.equalsIgnoreCase("double")) {- filter = LegacyNumericRangeQuery.newDoubleRange(field, precisionStep, Double- .valueOf(lowerTerm), Double.valueOf(upperTerm), lowerInclusive,+ filter = LegacyNumericRangeQuery.newDoubleRange(field, precisionStep,+ (lowerTerm == null ? null : Double.valueOf(lowerTerm)),+ (upperTerm == null ? null : Double.valueOf(upperTerm)),+ lowerInclusive,upperInclusive);} else if (type.equalsIgnoreCase("float")) {- filter = LegacyNumericRangeQuery.newFloatRange(field, precisionStep, Float- .valueOf(lowerTerm), Float.valueOf(upperTerm), lowerInclusive,+ filter = LegacyNumericRangeQuery.newFloatRange(field, precisionStep,+ (lowerTerm == null ? null : Float.valueOf(lowerTerm)),+ (upperTerm == null ? null : Float.valueOf(upperTerm)),+ lowerInclusive,upperInclusive);} else {throw new ParserException("type attribute must be one of: [long, int, double, float]");diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/PointRangeQueryBuilder.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/PointRangeQueryBuilder.javaindex 45483168bac..82f7039f0be 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/PointRangeQueryBuilder.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/PointRangeQueryBuilder.java@@ -46,14 +46,14 @@ import org.w3c.dom.Element;* <tr>* <td>lowerTerm</td>* <td>Specified by <tt>type</tt></td>- * <td>Yes</td>- * <td>N/A</td>+ * <td>No</td>+ * <td>Integer.MIN_VALUE Long.MIN_VALUE Float.NEGATIVE_INFINITY Double.NEGATIVE_INFINITY</td>* </tr>* <tr>* <td>upperTerm</td>* <td>Specified by <tt>type</tt></td>- * <td>Yes</td>- * <td>N/A</td>+ * <td>No</td>+ * <td>Integer.MAX_VALUE Long.MAX_VALUE Float.POSITIVE_INFINITY Double.POSITIVE_INFINITY</td>* </tr>* <tr>* <td>type</td>@@ -72,19 +72,27 @@ public class PointRangeQueryBuilder implements QueryBuilder {@Overridepublic Query getQuery(Element e) throws ParserException {String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");- String lowerTerm = DOMUtils.getAttributeOrFail(e, "lowerTerm");- String upperTerm = DOMUtils.getAttributeOrFail(e, "upperTerm");+ final String lowerTerm = DOMUtils.getAttribute(e, "lowerTerm", null);+ final String upperTerm = DOMUtils.getAttribute(e, "upperTerm", null);String type = DOMUtils.getAttribute(e, "type", "int");try {if (type.equalsIgnoreCase("int")) {- return IntPoint.newRangeQuery(field, Integer.valueOf(lowerTerm), Integer.valueOf(upperTerm));+ return IntPoint.newRangeQuery(field,+ (lowerTerm == null ? Integer.MIN_VALUE : Integer.valueOf(lowerTerm)),+ (upperTerm == null ? Integer.MAX_VALUE : Integer.valueOf(upperTerm)));} else if (type.equalsIgnoreCase("long")) {- return LongPoint.newRangeQuery(field, Long.valueOf(lowerTerm), Long.valueOf(upperTerm));+ return LongPoint.newRangeQuery(field,+ (lowerTerm == null ? Long.MIN_VALUE : Long.valueOf(lowerTerm)),+ (upperTerm == null ? Long.MAX_VALUE : Long.valueOf(upperTerm)));} else if (type.equalsIgnoreCase("double")) {- return DoublePoint.newRangeQuery(field, Double.valueOf(lowerTerm), Double.valueOf(upperTerm));+ return DoublePoint.newRangeQuery(field,+ (lowerTerm == null ? Double.NEGATIVE_INFINITY : Double.valueOf(lowerTerm)),+ (upperTerm == null ? Double.POSITIVE_INFINITY : Double.valueOf(upperTerm)));} else if (type.equalsIgnoreCase("float")) {- return FloatPoint.newRangeQuery(field, Float.valueOf(lowerTerm), Float.valueOf(upperTerm));+ return FloatPoint.newRangeQuery(field,+ (lowerTerm == null ? Float.NEGATIVE_INFINITY : Float.valueOf(lowerTerm)),+ (upperTerm == null ? Float.POSITIVE_INFINITY : Float.valueOf(upperTerm)));} else {throw new ParserException("type attribute must be one of: [long, int, double, float]");}diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutLowerTerm.xml b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutLowerTerm.xmlnew file mode 100644index 00000000000..54de55fd0f3--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutLowerTerm.xml@@ -0,0 +1,31 @@+<?xml version="1.0" encoding="UTF-8"?>+<!--+ 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.+-->+<BooleanQuery fieldName="contents">+ <Clause occurs="should">+ <TermQuery>merger</TermQuery>+ </Clause>+ <Clause occurs="mustnot">+ <TermQuery >sumitomo</TermQuery>+ </Clause>+ <Clause occurs="must">+ <TermQuery>bank</TermQuery>+ </Clause>+ <Clause occurs="must">+ <LegacyNumericRangeQuery fieldName="date2" upperTerm="19870412"/>+ </Clause>+</BooleanQuery>diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutRange.xml b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutRange.xmlnew file mode 100644index 00000000000..764f6548d76--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutRange.xml@@ -0,0 +1,31 @@+<?xml version="1.0" encoding="UTF-8"?>+<!--+ 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.+-->+<BooleanQuery fieldName="contents">+ <Clause occurs="should">+ <TermQuery>merger</TermQuery>+ </Clause>+ <Clause occurs="mustnot">+ <TermQuery >sumitomo</TermQuery>+ </Clause>+ <Clause occurs="must">+ <TermQuery>bank</TermQuery>+ </Clause>+ <Clause occurs="must">+ <LegacyNumericRangeQuery fieldName="date2"/>+ </Clause>+</BooleanQuery>diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutUpperTerm.xml b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutUpperTerm.xmlnew file mode 100644index 00000000000..d3a61c183b3--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/LegacyNumericRangeQueryWithoutUpperTerm.xml@@ -0,0 +1,31 @@+<?xml version="1.0" encoding="UTF-8"?>+<!--+ 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.+-->+<BooleanQuery fieldName="contents">+ <Clause occurs="should">+ <TermQuery>merger</TermQuery>+ </Clause>+ <Clause occurs="mustnot">+ <TermQuery >sumitomo</TermQuery>+ </Clause>+ <Clause occurs="must">+ <TermQuery>bank</TermQuery>+ </Clause>+ <Clause occurs="must">+ <LegacyNumericRangeQuery fieldName="date2" lowerTerm="19870409"/>+ </Clause>+</BooleanQuery>diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutLowerTerm.xml b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutLowerTerm.xmlnew file mode 100644index 00000000000..2159c2cee05--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutLowerTerm.xml@@ -0,0 +1,31 @@+<?xml version="1.0" encoding="UTF-8"?>+<!--+ 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.+-->+<BooleanQuery fieldName="contents">+ <Clause occurs="should">+ <TermQuery>merger</TermQuery>+ </Clause>+ <Clause occurs="mustnot">+ <TermQuery >sumitomo</TermQuery>+ </Clause>+ <Clause occurs="must">+ <TermQuery>bank</TermQuery>+ </Clause>+ <Clause occurs="must">+ <PointRangeQuery fieldName="date3" upperTerm="19870412"/>+ </Clause>+</BooleanQuery>diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutRange.xml b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutRange.xmlnew file mode 100644index 00000000000..dc18953358f--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutRange.xml@@ -0,0 +1,31 @@+<?xml version="1.0" encoding="UTF-8"?>+<!--+ 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.+-->+<BooleanQuery fieldName="contents">+ <Clause occurs="should">+ <TermQuery>merger</TermQuery>+ </Clause>+ <Clause occurs="mustnot">+ <TermQuery >sumitomo</TermQuery>+ </Clause>+ <Clause occurs="must">+ <TermQuery>bank</TermQuery>+ </Clause>+ <Clause occurs="must">+ <PointRangeQuery fieldName="date3"/>+ </Clause>+</BooleanQuery>diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutUpperTerm.xml b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutUpperTerm.xmlnew file mode 100644index 00000000000..eca8573265f--- /dev/null+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/PointRangeQueryWithoutUpperTerm.xml@@ -0,0 +1,31 @@+<?xml version="1.0" encoding="UTF-8"?>+<!--+ 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.+-->+<BooleanQuery fieldName="contents">+ <Clause occurs="should">+ <TermQuery>merger</TermQuery>+ </Clause>+ <Clause occurs="mustnot">+ <TermQuery >sumitomo</TermQuery>+ </Clause>+ <Clause occurs="must">+ <TermQuery>bank</TermQuery>+ </Clause>+ <Clause occurs="must">+ <PointRangeQuery fieldName="date3" lowerTerm="19870409"/>+ </Clause>+</BooleanQuery>diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.javaindex 82426d06076..4cf5fcffe2f 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestCoreParser.java@@ -132,12 +132,42 @@ public class TestCoreParser extends LuceneTestCase {Query q = parse("LegacyNumericRangeQuery.xml");dumpResults("LegacyNumericRangeQuery", q, 5);}++ public void testNumericRangeQueryXMLWithoutLowerTerm() throws ParserException, IOException {+ Query q = parse("LegacyNumericRangeQueryWithoutLowerTerm.xml");+ dumpResults("LegacyNumericRangeQueryWithoutLowerTerm", q, 5);+ }++ public void testNumericRangeQueryXMLWithoutUpperTerm() throws ParserException, IOException {+ Query q = parse("LegacyNumericRangeQueryWithoutUpperTerm.xml");+ dumpResults("LegacyNumericRangeQueryWithoutUpperTerm", q, 5);+ }++ public void testNumericRangeQueryXMLWithoutRange() throws ParserException, IOException {+ Query q = parse("LegacyNumericRangeQueryWithoutRange.xml");+ dumpResults("LegacyNumericRangeQueryWithoutRange", q, 5);+ }public void testPointRangeQuery() throws ParserException, IOException {Query q = parse("PointRangeQuery.xml");dumpResults("PointRangeQuery", q, 5);}+ public void testPointRangeQueryWithoutLowerTerm() throws ParserException, IOException {+ Query q = parse("PointRangeQueryWithoutLowerTerm.xml");+ dumpResults("PointRangeQueryWithoutLowerTerm", q, 5);+ }++ public void testPointRangeQueryWithoutUpperTerm() throws ParserException, IOException {+ Query q = parse("PointRangeQueryWithoutUpperTerm.xml");+ dumpResults("PointRangeQueryWithoutUpperTerm", q, 5);+ }++ public void testPointRangeQueryWithoutRange() throws ParserException, IOException {+ Query q = parse("PointRangeQueryWithoutRange.xml");+ dumpResults("PointRangeQueryWithoutRange", q, 5);+ }+//================= Helper methods ===================================protected String defaultField() {