Hello, Why is q=$JOIN_QUERY parsed differently than q=($JOIN_QUERY) where $JOIN_QUERY is a query with a join? In other words, why does adding enclosing parentheses change the query?
Context: There are two cores: parent and child. In the parent core: { "p": "p1", "x_s": "x1" } In the child core: { "id": "c1", "p_id_s": "p1", "y_s": "y1", "z_s": "z1" } The following query returns p1 (which is expected): q={!join fromIndex=child from=p_id_s to=id}y_s:y1 AND z_s:z1 The following query returns nothing (which is not expected): q=({!join fromIndex=child from=p_id_s to=id}y_s:y1 AND z_s:z1) See below for the complete test case. Thank you, Mathieu Larose /* * 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. */ package org.apache.solr.search.join; import com.google.common.collect.ImmutableMap; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.common.params.SolrParams; import org.apache.solr.core.SolrCore; import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.servlet.DirectSolrConnection; import org.junit.BeforeClass; import org.junit.Test; public class JoinTest extends SolrTestCaseJ4 { private static SolrCore parentCore; private static SolrCore childCore; @BeforeClass public static void beforeTests() throws Exception { initCore("solrconfig.xml", "schema_latest.xml", TEST_HOME(), "collection1"); parentCore = h.getCoreContainer().create("parent", ImmutableMap.of("configSet", "minimal")); update(parentCore, add(doc("id", "p1", "x_s", "x1"))); update(parentCore, commit()); childCore = h.getCoreContainer().create("child", ImmutableMap.of("configSet", "minimal")); update(childCore, add(doc("id", "c1", "p_id_s", "p1", "y_s", "y1", "z_s", "z1"))); update(childCore, commit()); } public static String update(SolrCore core, String xml) throws Exception { DirectSolrConnection connection = new DirectSolrConnection(core); SolrRequestHandler handler = core.getRequestHandler("/update"); return connection.request(handler, null, xml); } /** * When a child match for multiple child filters it returns the parent */ @Test public void whenAChildMatchForMultipleChildFiltersItReturnsTheParent() throws Exception { SolrParams solrParams = new SolrQuery("q", "{!join fromIndex=child from=p_id_s to=id}y_s:y1 AND z_s:z1", "qt", "/select", "wt", "json", "indent", "true", "fl", "id"); LocalSolrQueryRequest queryRequest = new LocalSolrQueryRequest(parentCore, solrParams); // OK assertJQ(queryRequest, "/response=={'numFound':1,'start':0,'docs':[{'id': 'p1'}]}"); } /** * When a child match for multiple child filters *with parentheses* it returns the parent * <p> * The only difference between this test and {@link JoinTest#whenAChildMatchForMultipleChildFiltersItReturnsTheParent} is the enclosing parentheses. */ @Test public void whenAChildMatchForMultipleChildFiltersWithParenthesesItReturnsTheParent() throws Exception { SolrParams solrParams = new SolrQuery("q", "({!join fromIndex=child from=p_id_s to=id}y_s:y1 AND z_s:z1)", "qt", "/select", "wt", "json", "indent", "true", "fl", "id"); LocalSolrQueryRequest queryRequest = new LocalSolrQueryRequest(parentCore, solrParams); // FAIL assertJQ(queryRequest, "/response=={'numFound':1,'start':0,'docs':[{'id': 'p1'}]}"); } }