Apache Lucene open-source search software
SOLR-8164: fix parsedquery debug output double-parens, add tests
Yonik Seeley8d2a0a135eb5
diff --git a/solr/core/src/java/org/apache/solr/search/QueryParsing.java b/solr/core/src/java/org/apache/solr/search/QueryParsing.javaindex 38433700ac1..cccffb20864 100644--- a/solr/core/src/java/org/apache/solr/search/QueryParsing.java+++ b/solr/core/src/java/org/apache/solr/search/QueryParsing.java@@ -507,23 +507,9 @@ public class QueryParsing {out.append('+');}Query subQuery = c.getQuery();- boolean wrapQuery = false;-- // TODO: may need to put parens around other types- // of queries too, depending on future syntax.- if (subQuery instanceof BooleanQuery) {- wrapQuery = true;- }-- if (wrapQuery) {- out.append('(');- }toString(subQuery, schema, out, subflag | FLAG_IS_CLAUSE);- if (wrapQuery) {- out.append(')');- }}if (needParens) {diff --git a/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.javaindex ebb8a8184aa..4cbd75c7fa4 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java@@ -239,8 +239,43 @@ public class DebugComponentTest extends SolrTestCaseJ4 {assertEquals("Expecting " + expectedRid + " but found " + rid, expectedRid, rid);}//The request ID is added to the debug/track section- assertEquals(rid, ((NamedList<Object>)rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID));+ assertEquals(rid, ((NamedList<Object>) rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID));//RID must be added to the toLog, so that it's included in the main request logassertEquals(rid, resp.getToLog().get(CommonParams.REQUEST_ID));}++ //+ // NOTE: String representations are not meant to be exact or backward compatible.+ // For example, foo:bar^3, foo:bar^3.0 and (foo:bar)^3 are equivalent. Use your+ // judgement when modifying these tests.+ //+ @Test+ public void testQueryToString() throws Exception {++ // test that both boosts are represented in a double-boost scenario+ assertQ(req("debugQuery", "true", "indent","true", "rows","0", "q", "(foo_s:aaa^3)^4"),+ "//str[@name='parsedquery'][.='foo_s:aaa^3.0^4.0']"+ );++ // test to see that extra parens are avoided+ assertQ(req("debugQuery", "true", "indent","true", "rows","0", "q", "+foo_s:aaa^3 -bar_s:bbb^0"),+ "//str[@name='parsedquery'][.='+foo_s:aaa^3.0 -bar_s:bbb^0.0']"+ );++ // test that parens are added when needed+ assertQ(req("debugQuery", "true", "indent", "true", "rows", "0", "q", "foo_s:aaa (bar_s:bbb baz_s:ccc)"),+ "//str[@name='parsedquery'][.='foo_s:aaa (bar_s:bbb baz_s:ccc)']"+ );++ // test boosts on subqueries+ assertQ(req("debugQuery", "true", "indent", "true", "rows", "0", "q", "foo_s:aaa^3 (bar_s:bbb baz_s:ccc)^4"),+ "//str[@name='parsedquery'][.='foo_s:aaa^3.0 (bar_s:bbb baz_s:ccc)^4.0']"+ );++ // test constant score query boost exists+ assertQ(req("debugQuery", "true", "indent", "true", "rows", "0", "q", "foo_s:aaa^=3"),+ "//str[@name='parsedquery'][contains(.,'3.0')]"+ );++ }}diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.javaindex e71ee194bdb..229c456ad56 100644--- a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java+++ b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java@@ -151,14 +151,12 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {,"/response/docs/[0]/id=='1'");- // boost should multiplyassertJQ(req("fq","id:1", "fl","id,score", "q", subqq+"^3", "qq","text:x^2", "debug","query"),"/debug/parsedquery_toString=='((text:x)^2.0)^3.0'");- // boost should multiplyassertJQ(req("fq","id:1", "fl","id,score", "q", " {!v=$qq}^3", "qq","text:x^2", "debug","query")