You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/05/14 16:46:02 UTC
svn commit: r1338231 - in /lucene/dev/trunk/solr:
core/src/java/org/apache/solr/search/JoinQParserPlugin.java
solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
Author: yonik
Date: Mon May 14 14:46:01 2012
New Revision: 1338231
URL: http://svn.apache.org/viewvc?rev=1338231&view=rev
Log:
SOLR-2824: parse query in fromCore for cross-core join
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java?rev=1338231&r1=1338230&r2=1338231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java Mon May 14 14:46:01 2012
@@ -31,6 +31,7 @@ import org.apache.solr.common.util.Simpl
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 Q
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 {
@Override
public 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) {
Modified: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java?rev=1338231&r1=1338230&r2=1338231&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java Mon May 14 14:46:01 2012
@@ -172,9 +172,8 @@ public abstract class MultiCoreExampleTe
// 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 time
String name = "core0";