Search in sources :

Example 1 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class TemporalEvaluatorsTest method testExplain.

@Test
public void testExplain() throws IOException {
    StreamExpression express = StreamExpressionParser.parse("month('myfield')");
    TemporalEvaluatorMonth datePartEvaluator = new TemporalEvaluatorMonth(express, factory);
    Explanation explain = datePartEvaluator.toExplanation(factory);
    assertEquals("month(myfield)", explain.getExpression());
    express = StreamExpressionParser.parse("day(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb)");
    TemporalEvaluatorDay dayPartEvaluator = new TemporalEvaluatorDay(express, factory);
    explain = dayPartEvaluator.toExplanation(factory);
    assertEquals("day(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb)", explain.getExpression());
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) TemporalEvaluatorDay(org.apache.solr.client.solrj.io.eval.TemporalEvaluatorDay) Explanation(org.apache.solr.client.solrj.io.stream.expr.Explanation) TemporalEvaluatorMonth(org.apache.solr.client.solrj.io.eval.TemporalEvaluatorMonth) Test(org.junit.Test)

Example 2 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class SignificantTermsStream method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    // functionName(collectionName, param1, param2, ..., paramN, sort="comp", [aliases="field=alias,..."])
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    // parameters
    for (Map.Entry<String, String> param : params.entrySet()) {
        expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
    }
    expression.addParameter(new StreamExpressionNamedParameter("field", field));
    expression.addParameter(new StreamExpressionNamedParameter("minDocFreq", Float.toString(minDocFreq)));
    expression.addParameter(new StreamExpressionNamedParameter("maxDocFreq", Float.toString(maxDocFreq)));
    expression.addParameter(new StreamExpressionNamedParameter("numTerms", String.valueOf(numTerms)));
    expression.addParameter(new StreamExpressionNamedParameter("minTermLength", String.valueOf(minTermLength)));
    // zkHost
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class RandomStream method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    // parameters
    for (Entry<String, String> param : props.entrySet()) {
        expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
    }
    // zkHost
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter)

Example 4 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class TextLogitStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    if (includeStreams && !(termsStream instanceof TermsStream)) {
        if (termsStream instanceof Expressible) {
            expression.addParameter(((Expressible) termsStream).toExpression(factory));
        } else {
            throw new IOException("This TextLogitStream contains a non-expressible TupleStream - it cannot be converted to an expression");
        }
    }
    // parameters
    for (Entry<String, String> param : params.entrySet()) {
        expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
    }
    expression.addParameter(new StreamExpressionNamedParameter("field", field));
    expression.addParameter(new StreamExpressionNamedParameter("name", name));
    if (termsStream instanceof TermsStream) {
        loadTerms();
        expression.addParameter(new StreamExpressionNamedParameter("terms", toString(terms)));
    }
    expression.addParameter(new StreamExpressionNamedParameter("outcome", outcome));
    if (weights != null) {
        expression.addParameter(new StreamExpressionNamedParameter("weights", toString(weights)));
    }
    expression.addParameter(new StreamExpressionNamedParameter("maxIterations", Integer.toString(maxIterations)));
    if (iteration > 0) {
        expression.addParameter(new StreamExpressionNamedParameter("iteration", Integer.toString(iteration)));
    }
    expression.addParameter(new StreamExpressionNamedParameter("positiveLabel", Integer.toString(positiveLabel)));
    expression.addParameter(new StreamExpressionNamedParameter("threshold", Double.toString(threshold)));
    // zkHost
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) IOException(java.io.IOException)

Example 5 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class StatsStream method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    // functionName(collectionName, param1, param2, ..., paramN, sort="comp", sum(fieldA), avg(fieldB))
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    // parameters
    ModifiableSolrParams mParams = new ModifiableSolrParams(params);
    for (Entry<String, String[]> param : mParams.getMap().entrySet()) {
        expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), String.join(",", param.getValue())));
    }
    // zkHost
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    // metrics
    for (Metric metric : metrics) {
        expression.addParameter(metric.toExpression(factory));
    }
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)82 Test (org.junit.Test)40 StreamExpressionNamedParameter (org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter)37 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)36 Tuple (org.apache.solr.client.solrj.io.Tuple)36 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)36 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)36 IOException (java.io.IOException)22 Expressible (org.apache.solr.client.solrj.io.stream.expr.Expressible)15 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)14 HashMap (java.util.HashMap)7 Map (java.util.Map)5 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)4 Metric (org.apache.solr.client.solrj.io.stream.metrics.Metric)4 MeanMetric (org.apache.solr.client.solrj.io.stream.metrics.MeanMetric)3 MinMetric (org.apache.solr.client.solrj.io.stream.metrics.MinMetric)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Explanation (org.apache.solr.client.solrj.io.stream.expr.Explanation)2