mirror of https://github.com/apache/lucene.git
SOLR-2757: min/max functions now take unlimited number of arguments
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1176097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1e554bd943
commit
9bdaa028d6
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.lucene.queries.function.valuesource;
|
||||||
|
|
||||||
|
import org.apache.lucene.queries.function.DocValues;
|
||||||
|
import org.apache.lucene.queries.function.ValueSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>MaxFloatFunction</code> returns the max of it's components.
|
||||||
|
*/
|
||||||
|
public class MaxFloatFunction extends MultiFloatFunction {
|
||||||
|
public MaxFloatFunction(ValueSource[] sources) {
|
||||||
|
super(sources);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String name() {
|
||||||
|
return "max";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float func(int doc, DocValues[] valsArr) {
|
||||||
|
boolean first = true;
|
||||||
|
float val = 0.0f;
|
||||||
|
for (DocValues vals : valsArr) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
val = vals.floatVal(doc);
|
||||||
|
} else {
|
||||||
|
val = Math.max(vals.floatVal(doc),val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.lucene.queries.function.valuesource;
|
||||||
|
|
||||||
|
import org.apache.lucene.queries.function.DocValues;
|
||||||
|
import org.apache.lucene.queries.function.ValueSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>MinFloatFunction</code> returns the min of it's components.
|
||||||
|
*/
|
||||||
|
public class MinFloatFunction extends MultiFloatFunction {
|
||||||
|
public MinFloatFunction(ValueSource[] sources) {
|
||||||
|
super(sources);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String name() {
|
||||||
|
return "min";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float func(int doc, DocValues[] valsArr) {
|
||||||
|
boolean first = true;
|
||||||
|
float val = 0.0f;
|
||||||
|
for (DocValues vals : valsArr) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
val = vals.floatVal(doc);
|
||||||
|
} else {
|
||||||
|
val = Math.min(vals.floatVal(doc),val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,7 +31,7 @@ Apache UIMA 2.3.1
|
||||||
Apache ZooKeeper 3.3.3
|
Apache ZooKeeper 3.3.3
|
||||||
|
|
||||||
|
|
||||||
Upgrading from Solr 3.4-dev
|
Upgrading from Solr 3.5-dev
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
* The Lucene index format has changed and as a result, once you upgrade,
|
* The Lucene index format has changed and as a result, once you upgrade,
|
||||||
|
@ -398,6 +398,9 @@ Bug Fixes
|
||||||
|
|
||||||
* LUCENE-3457: Upgrade commons-compress to 1.2 (Doron Cohen)
|
* LUCENE-3457: Upgrade commons-compress to 1.2 (Doron Cohen)
|
||||||
|
|
||||||
|
* SOLR-2757: min() and max() functions now support an arbitrary number of
|
||||||
|
ValueSources (Bill Bell via hossman)
|
||||||
|
|
||||||
================== 3.4.0 ==================
|
================== 3.4.0 ==================
|
||||||
|
|
||||||
Upgrading from Solr 3.3
|
Upgrading from Solr 3.3
|
||||||
|
|
|
@ -483,19 +483,20 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
|
||||||
return Math.atan2(a.doubleVal(doc), b.doubleVal(doc));
|
return Math.atan2(a.doubleVal(doc), b.doubleVal(doc));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addParser(new Double2Parser("max") {
|
addParser("max", new ValueSourceParser() {
|
||||||
@Override
|
@Override
|
||||||
public double func(int doc, DocValues a, DocValues b) {
|
public ValueSource parse(FunctionQParser fp) throws ParseException {
|
||||||
return Math.max(a.doubleVal(doc), b.doubleVal(doc));
|
List<ValueSource> sources = fp.parseValueSourceList();
|
||||||
|
return new MaxFloatFunction(sources.toArray(new ValueSource[sources.size()]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addParser(new Double2Parser("min") {
|
addParser("min", new ValueSourceParser() {
|
||||||
@Override
|
@Override
|
||||||
public double func(int doc, DocValues a, DocValues b) {
|
public ValueSource parse(FunctionQParser fp) throws ParseException {
|
||||||
return Math.min(a.doubleVal(doc), b.doubleVal(doc));
|
List<ValueSource> sources = fp.parseValueSourceList();
|
||||||
|
return new MinFloatFunction(sources.toArray(new ValueSource[sources.size()]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addParser("sqedist", new ValueSourceParser() {
|
addParser("sqedist", new ValueSourceParser() {
|
||||||
@Override
|
@Override
|
||||||
public ValueSource parse(FunctionQParser fp) throws ParseException {
|
public ValueSource parse(FunctionQParser fp) throws ParseException {
|
||||||
|
|
|
@ -571,7 +571,9 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
|
||||||
dofunc("sqrt(9)", Math.sqrt(9));
|
dofunc("sqrt(9)", Math.sqrt(9));
|
||||||
dofunc("cbrt(8)", Math.cbrt(8));
|
dofunc("cbrt(8)", Math.cbrt(8));
|
||||||
dofunc("max(0,1)", Math.max(0,1));
|
dofunc("max(0,1)", Math.max(0,1));
|
||||||
|
dofunc("max(10,3,8,7,5,4)", Math.max(Math.max(Math.max(Math.max(Math.max(10,3),8),7),5),4));
|
||||||
dofunc("min(0,1)", Math.min(0,1));
|
dofunc("min(0,1)", Math.min(0,1));
|
||||||
|
dofunc("min(10,3,8,7,5,4)", Math.min(Math.min(Math.min(Math.min(Math.min(10,3),8),7),5),4));
|
||||||
dofunc("log(100)", Math.log10(100));
|
dofunc("log(100)", Math.log10(100));
|
||||||
dofunc("ln(3)", Math.log(3));
|
dofunc("ln(3)", Math.log(3));
|
||||||
dofunc("exp(1)", Math.exp(1));
|
dofunc("exp(1)", Math.exp(1));
|
||||||
|
|
Loading…
Reference in New Issue