mirror of https://github.com/apache/lucene.git
LUCENE-10534: MinFloatFunction / MaxFloatFunction calls exists twice (#837)
This commit is contained in:
parent
d9d2cb6f09
commit
7efac761f4
|
@ -130,6 +130,8 @@ Optimizations
|
||||||
|
|
||||||
* LUCENE-10542: FieldSource exists implementations can avoid value retrieval (Kevin Risden)
|
* LUCENE-10542: FieldSource exists implementations can avoid value retrieval (Kevin Risden)
|
||||||
|
|
||||||
|
* LUCENE-10534: MinFloatFunction / MaxFloatFunction exists check can be slow (Kevin Risden)
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
---------------------
|
---------------------
|
||||||
* LUCENE-10477: Highlighter: WeightedSpanTermExtractor.extractWeightedSpanTerms to Query#rewrite
|
* LUCENE-10477: Highlighter: WeightedSpanTermExtractor.extractWeightedSpanTerms to Query#rewrite
|
||||||
|
|
|
@ -33,14 +33,17 @@ public class MaxFloatFunction extends MultiFloatFunction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float func(int doc, FunctionValues[] valsArr) throws IOException {
|
protected float func(int doc, FunctionValues[] valsArr) throws IOException {
|
||||||
if (!exists(doc, valsArr)) return 0.0f;
|
boolean noneFound = true;
|
||||||
|
|
||||||
float val = Float.NEGATIVE_INFINITY;
|
float val = Float.NEGATIVE_INFINITY;
|
||||||
for (FunctionValues vals : valsArr) {
|
for (FunctionValues vals : valsArr) {
|
||||||
if (vals.exists(doc)) {
|
if (vals.exists(doc)) {
|
||||||
|
noneFound = false;
|
||||||
val = Math.max(vals.floatVal(doc), val);
|
val = Math.max(vals.floatVal(doc), val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (noneFound) {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,17 @@ public class MinFloatFunction extends MultiFloatFunction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float func(int doc, FunctionValues[] valsArr) throws IOException {
|
protected float func(int doc, FunctionValues[] valsArr) throws IOException {
|
||||||
if (!exists(doc, valsArr)) return 0.0f;
|
boolean noneFound = true;
|
||||||
|
|
||||||
float val = Float.POSITIVE_INFINITY;
|
float val = Float.POSITIVE_INFINITY;
|
||||||
for (FunctionValues vals : valsArr) {
|
for (FunctionValues vals : valsArr) {
|
||||||
if (vals.exists(doc)) {
|
if (vals.exists(doc)) {
|
||||||
|
noneFound = false;
|
||||||
val = Math.min(vals.floatVal(doc), val);
|
val = Math.min(vals.floatVal(doc), val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (noneFound) {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -380,42 +380,66 @@ public class TestValueSources extends LuceneTestCase {
|
||||||
ValueSource vs =
|
ValueSource vs =
|
||||||
new MaxFloatFunction(
|
new MaxFloatFunction(
|
||||||
new ValueSource[] {new ConstValueSource(1f), new ConstValueSource(2f)});
|
new ValueSource[] {new ConstValueSource(1f), new ConstValueSource(2f)});
|
||||||
|
|
||||||
assertHits(new FunctionQuery(vs), new float[] {2f, 2f});
|
|
||||||
assertAllExist(vs);
|
assertAllExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {2f, 2f});
|
||||||
|
|
||||||
// as long as one value exists, then max exists
|
// as long as one value exists, then max exists
|
||||||
vs = new MaxFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2F)});
|
vs = new MaxFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2f)});
|
||||||
assertAllExist(vs);
|
assertAllExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {2f, 2f});
|
||||||
|
|
||||||
vs =
|
vs =
|
||||||
new MaxFloatFunction(
|
new MaxFloatFunction(
|
||||||
new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2F), BOGUS_DOUBLE_VS});
|
new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2f), BOGUS_DOUBLE_VS});
|
||||||
assertAllExist(vs);
|
assertAllExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {2f, 2f});
|
||||||
|
|
||||||
// if none exist, then max doesn't exist
|
// if none exist, then max doesn't exist
|
||||||
vs = new MaxFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, BOGUS_INT_VS, BOGUS_DOUBLE_VS});
|
vs = new MaxFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, BOGUS_INT_VS, BOGUS_DOUBLE_VS});
|
||||||
assertNoneExist(vs);
|
assertNoneExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {0f, 0f});
|
||||||
|
|
||||||
|
// if no values exist should return 0f even if value returned is non zero
|
||||||
|
vs =
|
||||||
|
new MaxFloatFunction(
|
||||||
|
new ValueSource[] {
|
||||||
|
new SumFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(42)})
|
||||||
|
});
|
||||||
|
assertNoneExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMinFloat() throws Exception {
|
public void testMinFloat() throws Exception {
|
||||||
ValueSource vs =
|
ValueSource vs =
|
||||||
new MinFloatFunction(
|
new MinFloatFunction(
|
||||||
new ValueSource[] {new ConstValueSource(1f), new ConstValueSource(2f)});
|
new ValueSource[] {new ConstValueSource(1f), new ConstValueSource(2f)});
|
||||||
|
|
||||||
assertHits(new FunctionQuery(vs), new float[] {1f, 1f});
|
|
||||||
assertAllExist(vs);
|
assertAllExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {1f, 1f});
|
||||||
|
|
||||||
// as long as one value exists, then min exists
|
// as long as one value exists, then min exists
|
||||||
vs = new MinFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2F)});
|
vs = new MinFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2f)});
|
||||||
assertHits(new FunctionQuery(vs), new float[] {2F, 2F});
|
|
||||||
assertAllExist(vs);
|
assertAllExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {2f, 2f});
|
||||||
|
|
||||||
vs =
|
vs =
|
||||||
new MinFloatFunction(
|
new MinFloatFunction(
|
||||||
new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2F), BOGUS_DOUBLE_VS});
|
new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(2f), BOGUS_DOUBLE_VS});
|
||||||
assertAllExist(vs);
|
assertAllExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {2f, 2f});
|
||||||
|
|
||||||
// if none exist, then min doesn't exist
|
// if none exist, then min doesn't exist
|
||||||
vs = new MinFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, BOGUS_INT_VS, BOGUS_DOUBLE_VS});
|
vs = new MinFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, BOGUS_INT_VS, BOGUS_DOUBLE_VS});
|
||||||
assertNoneExist(vs);
|
assertNoneExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {0f, 0f});
|
||||||
|
|
||||||
|
// if no values exist should return 0f even if value returned is non zero
|
||||||
|
vs =
|
||||||
|
new MinFloatFunction(
|
||||||
|
new ValueSource[] {
|
||||||
|
new SumFloatFunction(new ValueSource[] {BOGUS_FLOAT_VS, new ConstValueSource(42)})
|
||||||
|
});
|
||||||
|
assertNoneExist(vs);
|
||||||
|
assertHits(new FunctionQuery(vs), new float[] {0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNorm() throws Exception {
|
public void testNorm() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue