mirror of https://github.com/apache/lucene.git
SOLR-2768: new "mod(x,y)" function for computing the modulus of two value sources
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1379225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7754d1d105
commit
59847bd6d2
|
@ -48,6 +48,9 @@ New Features
|
|||
* SOLR-3670: New CountFieldValuesUpdateProcessorFactory makes it easy to index
|
||||
the number of values in another field for later use at query time. (hossman)
|
||||
|
||||
* SOLR-2768: new "mod(x,y)" function for computing the modulus of two value
|
||||
sources. (hossman)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -177,6 +177,23 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
|
|||
return new DivFloatFunction(a, b);
|
||||
}
|
||||
});
|
||||
addParser("mod", new ValueSourceParser() {
|
||||
@Override
|
||||
public ValueSource parse(FunctionQParser fp) throws ParseException {
|
||||
ValueSource a = fp.parseValueSource();
|
||||
ValueSource b = fp.parseValueSource();
|
||||
return new DualFloatFunction(a, b) {
|
||||
@Override
|
||||
protected String name() {
|
||||
return "mod";
|
||||
}
|
||||
@Override
|
||||
protected float func(int doc, FunctionValues aVals, FunctionValues bVals) {
|
||||
return aVals.floatVal(doc) % bVals.floatVal(doc);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
addParser("map", new ValueSourceParser() {
|
||||
@Override
|
||||
public ValueSource parse(FunctionQParser fp) throws ParseException {
|
||||
|
|
|
@ -329,6 +329,13 @@ public class QueryEqualityTest extends SolrTestCaseJ4 {
|
|||
"div(field(foo_i), sub(4,bar_i))");
|
||||
|
||||
}
|
||||
public void testFuncMod() throws Exception {
|
||||
assertFuncEquals("mod(5,4)", "mod(5, 4)");
|
||||
assertFuncEquals("mod(foo_i,4)", "mod(foo_i, 4)",
|
||||
"mod(field('foo_i'), 4)");
|
||||
assertFuncEquals("mod(foo_i,sub(4,field('bar_i')))",
|
||||
"mod(field(foo_i), sub(4,bar_i))");
|
||||
}
|
||||
public void testFuncMap() throws Exception {
|
||||
assertFuncEquals("map(field(foo_i), 0, 45, 100)",
|
||||
"map(foo_i, 0.0, 45, 100)");
|
||||
|
|
Loading…
Reference in New Issue