Apache Lucene open-source search software
SOLR-2824: parse query in fromCore for cross-core join
Yonik Seeley9d70bf609b6d
diff --git a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.javaindex dc7970e74c2..944ac2fed00 100644--- a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java@@ -31,6 +31,7 @@ import org.apache.solr.common.util.SimpleOrderedMap;import org.apache.solr.core.CoreContainer;import org.apache.solr.core.SolrCore;import org.apache.solr.handler.component.ResponseBuilder;+import org.apache.solr.request.LocalSolrQueryRequest;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrRequestInfo;import org.apache.solr.schema.TrieField;@@ -57,8 +58,30 @@ public class JoinQParserPlugin extends QParserPlugin {String fromIndex = getParam("fromIndex");String toField = getParam("to");String v = localParams.get("v");- QParser fromQueryParser = subQuery(v, null);- Query fromQuery = fromQueryParser.getQuery();+ Query fromQuery;++ if (fromIndex != null) {+ CoreContainer container = req.getCore().getCoreDescriptor().getCoreContainer();++ final SolrCore fromCore = container.getCore(fromIndex);++ if (fromCore == null) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core " + fromIndex);+ }++ LocalSolrQueryRequest otherReq = new LocalSolrQueryRequest(fromCore, params);+ try {+ QParser parser = QParser.getParser(v, "lucene", otherReq);+ fromQuery = parser.getQuery();+ } finally {+ otherReq.close();+ fromCore.close();+ }+ } else {+ QParser fromQueryParser = subQuery(v, null);+ fromQuery = fromQueryParser.getQuery();+ }+JoinQuery jq = new JoinQuery(fromField, toField, fromIndex, fromQuery);return jq;}@@ -90,7 +113,6 @@ class JoinQuery extends Query {@Overridepublic void extractTerms(Set terms) {- q.extractTerms(terms);}public Weight createWeight(IndexSearcher searcher) throws IOException {@@ -124,7 +146,7 @@ class JoinQuery extends Query {final SolrCore fromCore = container.getCore(fromIndex);if (fromCore == null) {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core ");+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core " + fromIndex);}if (info.getReq().getCore() == fromCore) {diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.javaindex b87a2f58984..86d25ec3a1d 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java@@ -172,9 +172,8 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase// test that no rewrite happens in core0 (if it does, it will rewrite to BBB1 and nothing will be found in core1)assertEquals( 2, getSolrCore0().query( new SolrQuery( "{!join from=type to=name fromIndex=core1}id:BB~" ) ).getResults().size() );- // test that query is parsed in the fromCore - TODO- // assertEquals( 2, getSolrCore0().query( new SolrQuery( "{!join from=type to=name fromIndex=core1}core1:yup" ) ).getResults().size() );-+ // test that query is parsed in the fromCore+ assertEquals( 2, getSolrCore0().query( new SolrQuery( "{!join from=type to=name fromIndex=core1}core1:yup" ) ).getResults().size() );// Now test reloading it should have a newer open timeString name = "core0";