SOLR-2972: Fix JoinQParser so it doesn't force the 'lucene' parser to be used for the sub query

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1215001 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2011-12-16 00:25:13 +00:00
parent 4d75ef3d42
commit b3d2c99128
2 changed files with 36 additions and 1 deletions

View File

@ -57,7 +57,7 @@ public class JoinQParserPlugin extends QParserPlugin {
String fromIndex = getParam("fromIndex");
String toField = getParam("to");
String v = localParams.get("v");
QParser fromQueryParser = subQuery(v, "lucene");
QParser fromQueryParser = subQuery(v, null);
Query fromQuery = fromQueryParser.getQuery();
JoinQuery jq = new JoinQuery(fromField, toField, fromIndex, fromQuery);
return jq;

View File

@ -18,6 +18,9 @@
package org.apache.solr;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.BooleanQuery;
import org.apache.noggit.JSONUtil;
import org.apache.noggit.ObjectBuilder;
import org.apache.solr.common.params.ModifiableSolrParams;
@ -27,6 +30,7 @@ import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.search.QParser;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -92,6 +96,37 @@ public class TestJoin extends SolrTestCaseJ4 {
assertJQ(req("q","{!join from=dept_s to=dept_id_s}title:MTS", "fl","id", "debugQuery","true")
,"/response=={'numFound':3,'start':0,'docs':[{'id':'10'},{'id':'12'},{'id':'13'}]}"
);
// expected outcome for a sub query matching dave joined against departments
final String davesDepartments =
"/response=={'numFound':2,'start':0,'docs':[{'id':'10'},{'id':'13'}]}";
// straight forward query
assertJQ(req("q","{!join from=dept_s to=dept_id_s}name:dave",
"fl","id"),
davesDepartments);
// variable deref for sub-query parsing
assertJQ(req("q","{!join from=dept_s to=dept_id_s v=$qq}",
"qq","{!dismax}dave",
"qf","name",
"fl","id",
"debugQuery","true"),
davesDepartments);
// variable deref for sub-query parsing w/localparams
assertJQ(req("q","{!join from=dept_s to=dept_id_s v=$qq}",
"qq","{!dismax qf=name}dave",
"fl","id",
"debugQuery","true"),
davesDepartments);
// defType local param to control sub-query parsing
assertJQ(req("q","{!join from=dept_s to=dept_id_s defType=dismax}dave",
"qf","name",
"fl","id",
"debugQuery","true"),
davesDepartments);
}