SOLR-12629: The predict evaluator should work with the polyfit function

This commit is contained in:
Joel Bernstein 2018-08-07 10:12:07 -04:00 committed by Joel
parent 3898653195
commit 2ca5a6d12e
2 changed files with 20 additions and 2 deletions

View File

@ -96,6 +96,11 @@ public class PolyFitEvaluator extends RecursiveNumericEvaluator implements ManyV
list.add(yvalue);
}
return list;
VectorFunction vec = new VectorFunction(pf, list);
vec.addToContext("x", x);
vec.addToContext("y", y);
return vec;
}
}

View File

@ -2856,7 +2856,8 @@ public class MathExpressionTest extends SolrCloudTestCase {
public void testPolyfit() throws Exception {
String cexpr = "let(echo=true," +
" a=array(0,1,2,3,4,5,6,7)," +
" fit=polyfit(a, 1))";
" fit=polyfit(a, 1)," +
" predictions=predict(fit, a))";
ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
paramsLoc.set("expr", cexpr);
paramsLoc.set("qt", "/stream");
@ -2876,6 +2877,18 @@ public class MathExpressionTest extends SolrCloudTestCase {
assertTrue(out.get(5).intValue() == 5);
assertTrue(out.get(6).intValue() == 6);
assertTrue(out.get(7).intValue() == 7);
out = (List<Number>)tuples.get(0).get("predictions");
assertTrue(out.size() == 8);
assertTrue(out.get(0).intValue() == 0);
assertTrue(out.get(1).intValue() == 1);
assertTrue(out.get(2).intValue() == 2);
assertTrue(out.get(3).intValue() == 3);
assertTrue(out.get(4).intValue() == 4);
assertTrue(out.get(5).intValue() == 5);
assertTrue(out.get(6).intValue() == 6);
assertTrue(out.get(7).intValue() == 7);
}
@Test