You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2017/06/08 18:52:03 UTC
lucene-solr:master: SOLR-10853:Allow the analyze Stream Evaluator to
operate outside of a stream
Repository: lucene-solr
Updated Branches:
refs/heads/master d411dceae -> 40ed09f8c
SOLR-10853:Allow the analyze Stream Evaluator to operate outside of a stream
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/40ed09f8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/40ed09f8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/40ed09f8
Branch: refs/heads/master
Commit: 40ed09f8caa40212f829d6916151f954033db953
Parents: d411dce
Author: Joel Bernstein <jb...@apache.org>
Authored: Thu Jun 8 13:13:05 2017 -0400
Committer: Joel Bernstein <jb...@apache.org>
Committed: Thu Jun 8 14:41:48 2017 -0400
----------------------------------------------------------------------
.../org/apache/solr/handler/AnalyzeEvaluator.java | 11 ++++++++---
solr/solr-ref-guide/src/stream-evaluators.adoc | 14 ++++++++++++++
.../solr/client/solrj/io/stream/TupStream.java | 3 +--
.../client/solrj/io/stream/StreamExpressionTest.java | 15 +++++++++++++++
4 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40ed09f8/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java b/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java
index c92f093..7c73498 100644
--- a/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java
+++ b/solr/core/src/java/org/apache/solr/handler/AnalyzeEvaluator.java
@@ -54,6 +54,7 @@ public class AnalyzeEvaluator extends SimpleEvaluator {
}
public void setStreamContext(StreamContext context) {
+ this.streamContext = context;
Object solrCoreObj = context.get("solr-core");
if (solrCoreObj == null || !(solrCoreObj instanceof SolrCore) ) {
throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "StreamContext must have SolrCore in solr-core key");
@@ -74,9 +75,13 @@ public class AnalyzeEvaluator extends SimpleEvaluator {
@Override
public Object evaluate(Tuple tuple) throws IOException {
- String value = tuple.getString(fieldName);
- if(value == null) {
- return null;
+ String value = null;
+ Object obj = tuple.get(fieldName);
+
+ if(obj == null) {
+ value = fieldName;
+ } else {
+ value = obj.toString();
}
List<String> tokens = new ArrayList();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40ed09f8/solr/solr-ref-guide/src/stream-evaluators.adoc
----------------------------------------------------------------------
diff --git a/solr/solr-ref-guide/src/stream-evaluators.adoc b/solr/solr-ref-guide/src/stream-evaluators.adoc
index 2c2a2ae..06c15df 100644
--- a/solr/solr-ref-guide/src/stream-evaluators.adoc
+++ b/solr/solr-ref-guide/src/stream-evaluators.adoc
@@ -20,6 +20,20 @@
// specific language governing permissions and limitations
// under the License.
+
+Stream evaluators are different the stream sources or stream decorators. Both
+streaming sources and stream decorators return streams of tuples.
+
+Stream evaluators are more like traditional functions that evaluates its parameters and
+returns an result. That result can be a single value, array, map or other structure.
+
+Stream evaluators can be nested to so that the output of evaluator becomes the input
+for another evaluatore.
+
+Stream evaluators can be called in different contexts. For example a stream evaluator
+can be called on its own or it can be called within the context of a streaming expression.
+
+
== analyze
// TODO
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40ed09f8/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TupStream.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TupStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TupStream.java
index f099e31..855f05f 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TupStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TupStream.java
@@ -170,8 +170,7 @@ public class TupStream extends TupleStream implements Expressible {
for(Entry<String,TupleStream> param : streamParams.entrySet()){
try{
- List<Tuple> streamTuples = new ArrayList<Tuple>();
-
+ List<Tuple> streamTuples = new ArrayList();
// open the stream, closed in finally block
param.getValue().open();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40ed09f8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
----------------------------------------------------------------------
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 3466af2..75f3637 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
@@ -5042,6 +5042,21 @@ public class StreamExpressionTest extends SolrCloudTestCase {
assertTrue(t.getString("test_t").equals("c"));
assertTrue(t.getString("id").equals("1"));
+
+ expr = "analyze(\"hello world\", test_t)";
+ paramsLoc = new ModifiableSolrParams();
+ paramsLoc.set("expr", expr);
+ paramsLoc.set("qt", "/stream");
+
+ solrStream = new SolrStream(url, paramsLoc);
+ context = new StreamContext();
+ solrStream.setStreamContext(context);
+ tuples = getTuples(solrStream);
+ assertEquals(tuples.size(), 1);
+ List terms = (List)tuples.get(0).get("return-value");
+ assertTrue(terms.get(0).equals("hello"));
+ assertTrue(terms.get(1).equals("world"));
+
//Try with single param
expr = "cartesianProduct(search("+COLLECTIONORALIAS+", q=\"*:*\", fl=\"id, test_t\", sort=\"id desc\"), analyze(test_t) as test_t)";
paramsLoc = new ModifiableSolrParams();