mirror of https://github.com/apache/lucene.git
SOLR-10731: Add k parameter
This commit is contained in:
parent
94731aaa09
commit
bdde9a163f
|
@ -47,6 +47,8 @@ import org.apache.solr.common.SolrDocumentList;
|
|||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
|
||||
import static org.apache.solr.common.params.CommonParams.Q;
|
||||
import static org.apache.solr.common.params.CommonParams.ROWS;
|
||||
|
||||
|
||||
public class KnnStream extends TupleStream implements Expressible {
|
||||
|
||||
|
@ -195,6 +197,13 @@ public class KnnStream extends TupleStream implements Expressible {
|
|||
}
|
||||
}
|
||||
|
||||
String k = params.get("k");
|
||||
|
||||
if(k != null) {
|
||||
params.add(ROWS, k);
|
||||
params.remove(k);
|
||||
}
|
||||
|
||||
params.add(Q, "{!mlt"+builder.toString()+"}"+id);
|
||||
|
||||
QueryRequest request = new QueryRequest(params);
|
||||
|
|
|
@ -942,6 +942,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
assertTrue(tuples.size() == 3);
|
||||
assertOrder(tuples, 2, 3, 4);
|
||||
|
||||
sParams = new ModifiableSolrParams(StreamingTest.mapParams(CommonParams.QT, "/stream"));
|
||||
sParams.add("expr", "knn(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", k=\"2\", fl=\"id, score\", mintf=\"1\")");
|
||||
solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);
|
||||
tuples = getTuples(solrStream);
|
||||
assertTrue(tuples.size() == 2);
|
||||
assertOrder(tuples, 2, 3);
|
||||
|
||||
sParams = new ModifiableSolrParams(StreamingTest.mapParams(CommonParams.QT, "/stream"));
|
||||
sParams.add("expr", "knn(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", rows=\"4\", fl=\"id, score\", mintf=\"1\", maxdf=\"0\")");
|
||||
solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);
|
||||
|
@ -955,7 +962,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
assertTrue(tuples.size() == 0);
|
||||
|
||||
sParams = new ModifiableSolrParams(StreamingTest.mapParams(CommonParams.QT, "/stream"));
|
||||
sParams.add("expr", "knn(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", rows=\"2\", fl=\"id, score\", mintf=\"1\", minwl=\"20\")");
|
||||
sParams.add("expr", "knn(" + COLLECTIONORALIAS + ", id=\"1\", qf=\"a_t\", r=\"2\", fl=\"id, score\", mintf=\"1\", minwl=\"20\")");
|
||||
solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/collection1", sParams);
|
||||
tuples = getTuples(solrStream);
|
||||
assertTrue(tuples.size() == 0);
|
||||
|
|
Loading…
Reference in New Issue