SOLR-8164: fix parsedquery debug output double-parens, add tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1710106 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2015-10-22 21:33:31 +00:00
parent ab3c1a48cd
commit 8d2a0a135e
3 changed files with 36 additions and 17 deletions

View File

@ -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) {

View File

@ -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 log
assertEquals(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')]"
);
}
}

View File

@ -151,14 +151,12 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {
,"/response/docs/[0]/id=='1'"
);
// boost should multiply
assertJQ(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 multiply
assertJQ(req("fq","id:1", "fl","id,score", "q", " {!v=$qq}^3", "qq","text:x^2"
, "debug","query"
)