From bdde9a163f6760c9cc7ef98c5a64fffcde1e2211 Mon Sep 17 00:00:00 2001 From: Joel Bernstein Date: Wed, 24 May 2017 20:04:20 -0400 Subject: [PATCH] SOLR-10731: Add k parameter --- .../apache/solr/client/solrj/io/stream/KnnStream.java | 9 +++++++++ .../client/solrj/io/stream/StreamExpressionTest.java | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java index 1d5f187e605..f2ba0b935a5 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/KnnStream.java @@ -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); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java index 04af631ef84..47b1d31e240 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java @@ -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);