Apache Solr open-source search software
SOLR-15156: [child childFilter='...:...'] no longer escapes (#2367)
David Smiley253b20c3c675
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex fcd5a3a4375..bfb00b66432 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -75,6 +75,9 @@ Improvements* SOLR-15011: /admin/logging handler will now propagate setLevel (log threshold) to all nodeswhen told to. The admin UI now tells it to. (Nazerke Seidan, David Smiley)+* SOLR-15156: [child] doc transformer's childFilter param no longer applies query syntax+ escaping. It was inconsistent with other Solr options. (David Smiley)+Other Changes----------------------* SOLR-14656: Autoscaling framework removed (Ishan Chattopadhyaya, noble, Ilan Ginzburg)diff --git a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.javaindex e841a59a798..d2a557ec144 100644--- a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java+++ b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java@@ -144,24 +144,24 @@ public class ChildDocTransformerFactory extends TransformerFactory {try {return QParser.getParser(qstr, req).getQuery();} catch (SyntaxError syntaxError) {- throw new SolrException(ErrorCode.BAD_REQUEST, "Failed to parse '" + param + "' param.");+ throw new SolrException(+ ErrorCode.BAD_REQUEST,+ "Failed to parse '" + param + "' param: " + syntaxError.getMessage(),+ syntaxError);}}- // NOTE: THIS FEATURE IS PRESENTLY EXPERIMENTAL; WAIT TO SEE IT IN THE REF GUIDE. FINAL SYNTAX IS TBD.protected static String processPathHierarchyQueryString(String queryString) {// if the filter includes a path string, build a lucene query string to match those specific child documents.// e.g. /toppings/ingredients/name_s:cocoa -> +_nest_path_:/toppings/ingredients +(name_s:cocoa)// ingredients/name_s:cocoa -> +_nest_path_:*/ingredients +(name_s:cocoa)int indexOfFirstColon = queryString.indexOf(':');if (indexOfFirstColon <= 0) {- return queryString;// give up+ return queryString; // regular filter, not hierarchy based.}int indexOfLastPathSepChar = queryString.lastIndexOf(PATH_SEP_CHAR, indexOfFirstColon);if (indexOfLastPathSepChar < 0) {- // regular filter, not hierarchy based.- return ClientUtils.escapeQueryChars(queryString.substring(0, indexOfFirstColon))- + ":" + ClientUtils.escapeQueryChars(queryString.substring(indexOfFirstColon + 1));+ return queryString; // regular filter, not hierarchy based.}final boolean isAbsolutePath = queryString.charAt(0) == PATH_SEP_CHAR;String path = ClientUtils.escapeQueryChars(queryString.substring(0, indexOfLastPathSepChar));diff --git a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.javaindex 02c1acad9fc..f1355238ef2 100644--- a/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java+++ b/solr/core/src/test/org/apache/solr/response/transform/TestChildDocTransformerHierarchy.java@@ -75,6 +75,21 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {assertU(commit());}+ @Test+ public void testNonTrivialChildFilter() throws Exception {+ // just check we don't throw an exception. This used to throw before SOLR-15152+ assertQ(+ req(+ "q",+ "*:*",+ "sort",+ "id asc",+ "fl",+ "*, _nest_path_, [child childFilter='type_s:Regular OR type_s:Chocolate']",+ "fq",+ fqToExcludeNonTestedDocs));+ }+@Testpublic void testParentFilterJSON() throws Exception {indexSampleData(numberOfDocsPerNestedTest);@@ -111,7 +126,7 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {public void testParentFilterLimitJSON() throws Exception {indexSampleData(numberOfDocsPerNestedTest);- try(SolrQueryRequest req = req("q", "type_s:donut", "sort", "id asc", "fl", "id, type_s, toppings, _nest_path_, [child childFilter='_nest_path_:/toppings' limit=1]",+ try(SolrQueryRequest req = req("q", "type_s:donut", "sort", "id asc", "fl", "id, type_s, toppings, _nest_path_, [child childFilter='{!field f=_nest_path_}/toppings' limit=1]","fq", fqToExcludeNonTestedDocs)) {BasicResultContext res = (BasicResultContext) h.queryAndResponse("/select", req).getResponse();Iterator<SolrDocument> docsStreamer = res.getProcessedDocuments();@@ -158,7 +173,7 @@ public class TestChildDocTransformerHierarchy extends SolrTestCaseJ4 {assertU(delQ("_nest_path_:\\/toppings"));assertU(commit());- try(SolrQueryRequest req = req("q", "type_s:donut", "sort", "id asc", "fl", "id, type_s, toppings, _nest_path_, [child childFilter='_nest_path_:/toppings' limit=1]",+ try(SolrQueryRequest req = req("q", "type_s:donut", "sort", "id asc", "fl", "id, type_s, toppings, _nest_path_, [child childFilter='_nest_path_:\\\\/toppings' limit=1]","fq", fqToExcludeNonTestedDocs)) {BasicResultContext res = (BasicResultContext) h.queryAndResponse("/select", req).getResponse();Iterator<SolrDocument> docsStreamer = res.getProcessedDocuments();diff --git a/solr/solr-ref-guide/src/major-changes-in-solr-9.adoc b/solr/solr-ref-guide/src/major-changes-in-solr-9.adocindex 79e6dc1150b..f5f79603826 100644--- a/solr/solr-ref-guide/src/major-changes-in-solr-9.adoc+++ b/solr/solr-ref-guide/src/major-changes-in-solr-9.adoc@@ -150,6 +150,9 @@ _(raw; not yet edited)_* SOLR-15121: XSLTResponseWriter moved to /contrib/scripting/ package insteadof shipping as part of Solr, due to security concerns.+* SOLR-15156: Child Doc Transformer's `childFilter` param no longer applies query syntax+escaping because it's inconsistent with the rest of Solr and was limiting. This refers to `[child childFilter='field:value']`.+=== Upgrade Prerequisites in Solr 9* Upgrade all collections in stateFormat=1 to stateFormat=2 *before* upgrading to Solr 9, as Solr 9 does not support the