SOLR-6248: Changing the format of mlt query parser

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1635329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Anshum Gupta 2014-10-29 23:10:17 +00:00
parent d49fb2f7ec
commit d7a1423439
6 changed files with 11 additions and 11 deletions

View File

@ -28,6 +28,7 @@ import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QueryParsing;
import java.io.IOException;
import java.util.ArrayList;
@ -42,7 +43,7 @@ public class CloudMLTQParser extends QParser {
}
public Query parse() {
String id = localParams.get("id");
String id = localParams.get(QueryParsing.V);
// Do a Real Time Get for the document
SolrDocument doc = getDocument(id);

View File

@ -23,7 +23,7 @@ import org.apache.solr.search.QParser;
import org.apache.solr.search.QParserPlugin;
/**
* Usage: {!mlt id=uniqueId qf=queryField1,queryField2}
* Usage: {!mlt qf=queryField1,queryField2}uniqueId
*/
public class MLTQParserPlugin extends QParserPlugin {
public static final String NAME = "mlt";

View File

@ -29,6 +29,7 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.QParser;
import org.apache.solr.search.QueryParsing;
import org.apache.solr.search.SolrIndexSearcher;
import java.io.IOException;
@ -45,7 +46,7 @@ public class SimpleMLTQParser extends QParser {
public Query parse() {
String defaultField = req.getSchema().getUniqueKeyField().getName();
String uniqueValue = localParams.get("id");
String uniqueValue = localParams.get(QueryParsing.V);
String[] qf = localParams.getParams("qf");
SolrIndexSearcher searcher = req.getSearcher();

View File

@ -842,14 +842,12 @@ public class QueryEqualityTest extends SolrTestCaseJ4 {
public void testQueryMLT() throws Exception {
assertU(adoc("id", "1", "lowerfilt", "sample data"));
assertU(commit());
SolrQueryRequest req = req("qf","lowerfilt","id","1");
try {
assertQueryEquals("mlt", req,
"{!mlt qf=lowerfilt id=1}");
assertQueryEquals("mlt", "{!mlt qf=lowerfilt}1",
"{!mlt qf=lowerfilt v=1}");
} finally {
delQ("*:*");
assertU(commit());
req.close();
}
}

View File

@ -82,7 +82,7 @@ public class CloudMLTQParserTest extends AbstractFullDistribZkTestBase {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CommonParams.Q, "{!mlt id=17 qf=lowerfilt}");
params.set(CommonParams.Q, "{!mlt qf=lowerfilt}17");
QueryResponse queryResponse = cloudClient.query(params);
SolrDocumentList solrDocuments = queryResponse.getResults();
int[] expectedIds = new int[]{17, 13, 14, 20, 22, 15, 16, 24, 18, 23};
@ -94,7 +94,7 @@ public class CloudMLTQParserTest extends AbstractFullDistribZkTestBase {
assertArrayEquals(expectedIds, actualIds);
params = new ModifiableSolrParams();
params.set(CommonParams.Q, "{!mlt id=3 qf=lowerfilt}");
params.set(CommonParams.Q, "{!mlt qf=lowerfilt}3");
queryResponse = queryServer(params);
solrDocuments = queryResponse.getResults();
expectedIds = new int[]{3, 27, 26, 28};
@ -106,7 +106,7 @@ public class CloudMLTQParserTest extends AbstractFullDistribZkTestBase {
assertArrayEquals(expectedIds, actualIds);
params = new ModifiableSolrParams();
params.set(CommonParams.Q, "{!mlt id=20 qf=lowerfilt}");
params.set(CommonParams.Q, "{!mlt qf=lowerfilt}20");
params.set("debug" , "query");
queryResponse = queryServer(params);
solrDocuments = queryResponse.getResults();

View File

@ -67,7 +67,7 @@ public class SimpleMLTQParserTest extends SolrTestCaseJ4 {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CommonParams.Q, "{!mlt id=17 qf=lowerfilt}");
params.set(CommonParams.Q, "{!mlt qf=lowerfilt}17");
assertQ(req(params),
"//result/doc[1]/int[@name='id'][.='17']",
"//result/doc[2]/int[@name='id'][.='13']",