(index) Avoid hypothetical divide-by-zero in tcfAvgDist

This commit is contained in:
Viktor Lofgren 2024-08-06 10:52:52 +02:00
parent 8569bb8e11
commit df6a05b9a7

View File

@ -345,7 +345,7 @@ public class IndexResultScoreCalculator {
+ keywordMinDistFac;
double tcfAvgDist = rankingParams.tcfAvgDist * (1.0 / calculateAvgMinDistance(positionsQuery, ctx));
double tcfFirstPosition = rankingParams.tcfFirstPosition * (1.0 / Math.sqrt(Math.max(1, firstPosition)));
double tcfFirstPosition = rankingParams.tcfFirstPosition * (1.0 / Math.sqrt(firstPosition));
double bM25 = rankingParams.bm25Weight * wordFlagsQuery.root.visit(new Bm25GraphVisitor(rankingParams.bm25Params, weightedCounts, length, ctx));
double bFlags = rankingParams.bm25Weight * wordFlagsQuery.root.visit(new TermFlagsGraphVisitor(rankingParams.bm25Params, wordFlagsQuery.data, weightedCounts, ctx));
@ -474,7 +474,7 @@ public class IndexResultScoreCalculator {
}
}
if (cnt > 0) {
if (cnt > 0 && sum > 0) {
return sum / cnt;
} else {
return 1000.;